Wicket
  1. Wicket
  2. WICKET-1429

AjaxFormSubmitBehavior doesn't work well with nested forms

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.3.2
    • Fix Version/s: None
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      Windows XP SP2, JDK 1.5, Apache Tomcat 6.0.14

      Description

      Hello everybody,

      I need to know if it's normal I get error when I do that :

      [code="TestPage.java"]
      public class TestPage extends WebPage {

      public TestPage() {
      Form f = new Form("f");
      f.add(new AjaxFormSubmitBehavior("onsubmit") {

      @Override
      protected void onSubmit(AjaxRequestTarget target)

      { throw new UnsupportedOperationException("Not supported yet."); }

      @Override
      protected void onError(AjaxRequestTarget target) { throw new UnsupportedOperationException("Not supported yet."); }

      });
      f.setOutputMarkupId(true);
      add(f);
      }
      }

      [code="TestPage.html"]
      <html>
      <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      </head>
      <body>
      <form wicket:id="f">
      <input type="submit" value="Sumbit"/>
      </form>
      </body>
      </html>

      I get a error message :
      WicketMessage: Exception in rendering component: [MarkupContainer [Component id = f, page = fr.pasteur.sig.wicket.bug.TestPage, path = 0:f.Form, isVisible = true, isVersioned = true]]

      Root cause:

      java.lang.IllegalStateException: form was not specified in the constructor and cannot be found in the hierarchy of the component this behavior is attached to
      at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.getForm(AjaxFormSubmitBehavior.java:85)
      at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.getEventHandler(AjaxFormSubmitBehavior.java:97)
      at org.apache.wicket.ajax.AjaxEventBehavior.onComponentTag(AjaxEventBehavior.java:108)
      at org.apache.wicket.behavior.AbstractAjaxBehavior.onComponentTag(AbstractAjaxBehavior.java:132)
      at org.apache.wicket.Component.renderComponentTag(Component.java:3807)
      at org.apache.wicket.Component.renderComponent(Component.java:2462)
      at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1411)
      at org.apache.wicket.markup.html.form.Form.onRender(Form.java:1692)
      at org.apache.wicket.Component.render(Component.java:2308)
      at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1297)
      at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1427)
      at org.apache.wicket.Page.onRender(Page.java:1460)
      at org.apache.wicket.Component.render(Component.java:2308)
      at org.apache.wicket.Page.renderPage(Page.java:906)
      at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.respond(BookmarkablePageRequestTarget.java:231)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:104)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1172)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1330)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:358)
      at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:595)

      Complete stack:

      org.apache.wicket.WicketRuntimeException: Exception in rendering component: [MarkupContainer [Component id = f, page = fr.pasteur.sig.wicket.bug.TestPage, path = 0:f.Form, isVisible = true, isVersioned = true]]
      at org.apache.wicket.Component.renderComponent(Component.java:2509)
      at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1411)
      at org.apache.wicket.markup.html.form.Form.onRender(Form.java:1692)
      at org.apache.wicket.Component.render(Component.java:2308)
      at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1297)
      at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1427)
      at org.apache.wicket.Page.onRender(Page.java:1460)
      at org.apache.wicket.Component.render(Component.java:2308)
      at org.apache.wicket.Page.renderPage(Page.java:906)
      at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.respond(BookmarkablePageRequestTarget.java:231)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:104)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1172)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1330)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:358)

      If I modify AjaxFormSubmitBehavior("onsubmit") by AjaxFormSubmitBehavior(f, "onsubmit) that work perfecty.

      Best regards.

      Dutrieux

        Activity

        Hide
        Gerolf Seitz added a comment -

        i can see why it's failing, but does it even make sense to attach an AjaxFormSubmitBehavior to a form's onsubmit event?
        usually this behavior is added to a formcomponent inside the form.

        Show
        Gerolf Seitz added a comment - i can see why it's failing, but does it even make sense to attach an AjaxFormSubmitBehavior to a form's onsubmit event? usually this behavior is added to a formcomponent inside the form.
        Hide
        Gerolf Seitz added a comment -

        and btw, there are no nested forms in your example

        Show
        Gerolf Seitz added a comment - and btw, there are no nested forms in your example
        Hide
        Gerolf Seitz added a comment -

        you shouldn't add the AjaxFormSubmitBehavior to the form. that really doesn't make any sense.

        Show
        Gerolf Seitz added a comment - you shouldn't add the AjaxFormSubmitBehavior to the form. that really doesn't make any sense.
        Hide
        Matthew Buckett added a comment -

        Just starting out with wicket I tried using a nested form and AjaxFormSubmitBahavior on the nested form. Seeing how the implementation of nested forms works (outputting a div for nested forms), having the AjaxFormSubmitBehaviour add an onsubmit handler to a div plainly isn't going to work.

        Would checking that AjaxFormSubmitBehaviour isn't added to a nested form helpful for debugging?

        Show
        Matthew Buckett added a comment - Just starting out with wicket I tried using a nested form and AjaxFormSubmitBahavior on the nested form. Seeing how the implementation of nested forms works (outputting a div for nested forms), having the AjaxFormSubmitBehaviour add an onsubmit handler to a div plainly isn't going to work. Would checking that AjaxFormSubmitBehaviour isn't added to a nested form helpful for debugging?
        Hide
        Martin Grigorov added a comment -

        Yes, this is a good idea. Please create a new ticket and attach a quickstart to it to save us some time.
        It wont work in all cases though. It is the same problem as Component#onInitialize() solves - when adding the behavior to the Form the Form itself may still not know its parent and thus there is no way to know that it is nested or not. So we can do this check as a best effort in DEVELOPMENT mode.

        Show
        Martin Grigorov added a comment - Yes, this is a good idea. Please create a new ticket and attach a quickstart to it to save us some time. It wont work in all cases though. It is the same problem as Component#onInitialize() solves - when adding the behavior to the Form the Form itself may still not know its parent and thus there is no way to know that it is nested or not. So we can do this check as a best effort in DEVELOPMENT mode.

          People

          • Assignee:
            Unassigned
            Reporter:
            Duto
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development