reset password
Author Message
e.laverdi
Posts: 15
Posted 13:11 Nov 05, 2009 |

Is formBackingObject necessary to get onSubmit to work? I decided to use handleRequestInternal to view the form but my submit button does not do anything.

    <bean name="/instructor/addOnlineAssignment.html"
        class="csns.spring.controller.instructor.AddOnlineAssignmentController">
        <property name="commandName" value="OnlineAssignment" />
        <property name="commandClass" value="csns.model.assignment.OnlineAssignment" />
        <property name="sectionDao" ref="sectionDao" />
        <property name="formView" value="instructor/addOnlineAssignment" />
        <property name="successView" value="redirect:/instructor/addOnlineAssignmentQuestions.html" />
    </bean>

Am I missing anything in the bean? I have been staring at this page and for hours now and no progress.

    protected ModelAndView onSubmit( HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors ) {
           
            OnlineAssignment onlineAssignment = (OnlineAssignment) command;
           
            return new ModelAndView( getSuccessView() );   
    }

I right now I am not actually adding the online assignment. I just want to be able to redirect the success view. Any tips?

 

cysun
Posts: 2935
Posted 13:20 Nov 05, 2009 |

Make sure the form method is "post", not "get".

The superclass SimpleFormController creates a backing object (i.e. command object) using the default (i.e. no argument) constructor of the command class specified in the bean specification. You don't need to override the formBackingObject method unless you want to create a command object in some other way.

e.laverdi
Posts: 15
Posted 13:41 Nov 05, 2009 |

    So the following should be enough to get me to the success view. I still dont understand why its not working hmmm.

    CONTROLLER

    protected ModelAndView onSubmit( HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors ) {
           
            return new ModelAndView( getSuccessView() );   
    }

    XML

    <bean name="/instructor/addOnlineAssignment.html"
        class="csns.spring.controller.instructor.AddOnlineAssignmentController">
        <property name="sectionDao" ref="sectionDao" />
        <property name="formView" value="instructor/addOnlineAssignment" />
        <property name="successView" value="redirect:/instructor/addOnlineAssignmentQuestions.html" />
    </bean>

    JSP

<form:form>
<input type="hidden" name="sectionId" value="${section.id}" />
<table border="0">

  <tr><td colspan="2"><input class="subbutton" type="submit" value="Next" /></td></tr>
</table>
</form:form>

 

e.laverdi
Posts: 15
Posted 13:43 Nov 05, 2009 |
cysun wrote:

Make sure the form method is "post", not "get".

The superclass SimpleFormController creates a backing object (i.e. command object) using the default (i.e. no argument) constructor of the command class specified in the bean specification. You don't need to override the formBackingObject method unless you want to create a command object in some other way.

Form automatically adds the post method.

jgreen
Posts: 23
Posted 14:20 Nov 05, 2009 |

Hey,

I had that same problem for a while, where I would hit submit but nothing happens. Then I realized that I had to include

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

so that it would recognize the form:form tag.

Just in case that helps...

cysun
Posts: 2935
Posted 14:34 Nov 05, 2009 |
jgreen wrote:

Hey,

I had that same problem for a while, where I would hit submit but nothing happens. Then I realized that I had to include

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

so that it would recognize the form:form tag.

Just in case that helps...

You shouldn't need to do that since the form tag lib is already included in WEB-INF/jsp/include/taglib.jspf, which you should include in your JSP.

cysun
Posts: 2935
Posted 14:37 Nov 05, 2009 |
e.laverdi wrote:

    So the following should be enough to get me to the success view. I still dont understand why its not working hmmm.

    CONTROLLER

    protected ModelAndView onSubmit( HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors ) {
           
            return new ModelAndView( getSuccessView() );   
    }

    XML

    <bean name="/instructor/addOnlineAssignment.html"
        class="csns.spring.controller.instructor.AddOnlineAssignmentController">
        <property name="sectionDao" ref="sectionDao" />
        <property name="formView" value="instructor/addOnlineAssignment" />
        <property name="successView" value="redirect:/instructor/addOnlineAssignmentQuestions.html" />
    </bean>

    JSP

<form:form>
<input type="hidden" name="sectionId" value="${section.id}" />
<table border="0">

  <tr><td colspan="2"><input class="subbutton" type="submit" value="Next" /></td></tr>
</table>
</form:form> 

You should have the commandName and commandClass in the bean specification. Also add the command name to the <form> tag, i.e. <form:form commandName="...">.

And do a "View Source" in your browser and see if the form is generated correctly.

Add a logging statement in onSubmit to see if the controller received the post request.

e.laverdi
Posts: 15
Posted 15:36 Nov 05, 2009 |

I seems like it kind find the OnlineAssignment class. Am I missing something? I checked the paths and are all correct. Attached is log

XML

    <bean name="/instructor/addOnlineAssignment.html"
        class="csns.spring.controller.instructor.AddOnlineAssignmentController">
        <property name="commandName" value="onlineAssignment" />
        <property name="commandClass" value="csns.model.assignment.OnlineAssignment" />
        <property name="sectionDao" ref="sectionDao" />
        <property name="formView" value="instructor/addOnlineAssignment" />
        <property name="successView" value="redirect:/instructor/addOnlineAssignmentQuestions.html" />
    </bean>

CONTROLLER

    public ModelAndView handleRequestInternal( HttpServletRequest request,
            HttpServletResponse response ) throws Exception {
       
        String sectionId = request.getParameter( "sectionId" );
        Section section = sectionDao.getSectionById( Integer.valueOf( sectionId ) );

        return (new ModelAndView( getFormView() )).addObject("section", section );
    }
   
    protected ModelAndView onSubmit( HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors ) {
       
        OnlineAssignment onlineAssignment = (OnlineAssignment) command;
        // note doing anything yet just want to process the success view to next page
           
        return new ModelAndView( getSuccessView() );   
    }

    public void setSectionDao( SectionDao sectionDao ) {
       
        this.sectionDao = sectionDao;
    }

JSP

<form:form commandName="onlineAssignment">
<input type="hidden" name="sectionId" value="${section.id}" />
<table border="0">

  <tr>
    <td>Name:</td>
    <td><form:input path="name" cssClass="leftinput" size="30" maxlength="255" /></td>
  </tr>
  <tr>
    <td>Description:</td>
    <td><form:input path="description" cssClass="leftinput" size="60" maxlength="255" /></td>
  </tr>

  <tr><td colspan="2"><input class="subbutton" type="submit" value="Next" /></td></tr>

</table>
</form:form>

Attachments:
Last edited by e.laverdi at 15:37 Nov 05, 2009.
cysun
Posts: 2935
Posted 15:42 Nov 05, 2009 |
e.laverdi wrote:

I seems like it kind find the OnlineAssignment class. Am I missing something? I checked the paths and are all correct. Attached is log

...

Does your OnlineAssignment class has a zero-argument constructor?

e.laverdi
Posts: 15
Posted 15:55 Nov 05, 2009 |

Yes it does.

cysun
Posts: 2935
Posted 16:58 Nov 05, 2009 |
e.laverdi wrote:

Yes it does.

Then try overriding the formBackingObject method.

e.laverdi
Posts: 15
Posted 17:11 Nov 05, 2009 |

Will do try that

cysun
Posts: 2935
Posted 17:18 Nov 05, 2009 |
e.laverdi wrote:

Will do try that

OK, I know what's going on. Your handleRequestInternal() returns a view directly, thus bypasses the superclass's formBackingObject(). You should set "section" as a request parameter, then return "super.handleRequestInternal( request, response )". See TakeSurveyController for a properly written handleRequestInternal(). Also note that the access modifier for handleRequestInternal() should be protected, not public. Be careful with method signatures, or use the annotation @Override to make sure that you are actually overriding a superclass method, not creating a new one.

e.laverdi
Posts: 15
Posted 17:36 Nov 05, 2009 |

Thank you will try that