Announcement Announcement Module
Collapse
No announcement yet.
onSubmit not called Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • onSubmit not called

    First, thanks for the great job done on Spring framework !

    Here is an extract of my configuration:

    test-servlet.xml:
    <property name="mappings">
    <props>
    <prop key="/addInsert.htm">addInsertFormController</prop>
    </props>
    </property>

    <bean id="addInsertFormController" class="test.web.AddInsertFormController">
    <property name="formView"><value>insertForm</value></property>
    <property name="successView"><value>welcomeMiddleSubView</value></property>
    </bean>

    views.properties:
    welcomeMiddleSubView.class=org.springframework.web .servlet.view.JstlView
    welcomeMiddleSubView.url=/WEB-INF/views/jsp/test/body.jsp

    Body.jsp is just text.

    The class AbstractTestFormController extends SimpleFormController and define:
    protected ModelAndView disallowDuplicateFormSubmission(HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    BindException errors = new BindException(formBackingObject(request), getCommandName());
    errors.reject("duplicateFormSubmission", null, "Duplicate form submission");
    return showForm(request, response, errors);
    }


    public class AddInsertFormController extends AbstractTestFormController {

    public AddInsertFormController() {
    // need a session to hold the formBackingObject
    setSessionForm(true);
    // initialize the form from the formBackingObject
    setBindOnNewForm(falsr);

    setValidateOnBinding(true);
    setCommandName("command");
    }

    protected Map referenceData(HttpServletRequest request) throws ServletException {}


    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
    return new AddInsertForm();
    }

    protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) {
    AddInsertForm form = (AddInsertForm) command;
    }

    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
    Object command, BindException errors) throws Exception {
    // never reached !!!? :/
    return new ModelAndView(getSuccessView());
    }
    }

    So it looks very simple. But when I click on the button, the method onSubmitin my controller is not called ! I 've checked with the debugger the methods referenceData, formBackingObject: they are called normally. But I can see onSubmit is never called. The method onbindAndValidate is never called also (even if I put setValidateOnBinding(true); )

    More than 1 week I'm on the problem. There must be an obvious mistake, but where...?
    Any help or idea will be greatly appreciated !
    Christophe

  • #2
    I forgot to put insertForm.jsp:
    <%@ include file="../include/includes.jsp" %>

    <P>
    <H2>Import Data:</H2>

    <spring:bind path="command">
    <FONT color="red">
    <B><c:out value="${status.errorMessage}"/></B>
    </FONT>
    </spring:bind>

    <FORM name="insertForm" action="<c:url value="/addInsert.htm"/>" method="POST">
    <spring:bind path="command.path">
    <FONT color="red">
    <B><c:out value="${status.errorMessage}"/></B>
    </FONT>
    <BR><INPUT type="text" maxlength="30" size="30" name="path" value="<c:out value="${status.value}"/>" >
    </spring:bind>

    <button name="submit" type="submit" value="submit">Set path</button>
    </FORM>

    Comment


    • #3
      i have the same problem.i havn't read the sourcecode of simpleformcontroller and its parent class.i guess there is something happend about commandclass

      Comment


      • #4
        Going deeper with the debugger, here is what I get:

        SimpleFormController:

        onSubmit(Object,BindException):
        -> return new ModelAndView("welcomeMiddleSubView",errors.getMode l());

        back to: onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)
        -> return onSubmit(AddInsertForm, errors);

        back torocessFormSubmission
        -> return onSubmit(request,response,command,errors)

        => Here my onSubmit should be called since it is overriden, it is not !!!

        back to AbstractFormController:
        handleRequestInternal(...)
        -> return processFormSubmission(request,response,command,bin der.getErrors());
        ...

        => The successView is shown but my onSubmit overiden method is not called.

        Comment


        • #5
          I had:
          import java.net.BindException
          instead of:
          import org.springframework.validation.BindException;

          Now it is working.

          Comment

          Working...
          X