Wicket
  1. Wicket
  2. WICKET-4

Page.onBeginRequest() [and consequently .onAttach()] not called when form on page is submitted.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.3.0-beta2
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      os = OS X 10.4.8; java version = jre/jdk 1.5.0_06; servlet container = jetty-5.1.11RC0

      Description

      Page.onBeginRequest() [and consequently .onAttach()] not called when form on page is submitted. Form.onBeginRequest() is not called as well. However, Page.onEndRequest() and Form.onEndRequest() are called correctly.

      In more detail:
      I have a page, FrontPage, and a form LoginForm on it (The form has defaultFormProcessing = true)
      onBeginRequest(), onEndRequest() in FrontPage, LoginForm, are overriden as follows:

      protected void onBeginRequest()

      { log.debug("request begin"); ... super.onBeginRequest(); }

      protected void onEndRequest()

      { super.onEndRequest(); ... log.debug("request end"); }

      So I load FrontPage, type in data into the form (that corr. to LoginForm) and submit form.
      The log output is as follows

      //first load of page
      DEBUG <hotline.pages.FrontPage> request begin
      ...
      DEBUG <hotline.pages.FrontPage$LoginForm> request begin
      ...
      DEBUG <hotline.pages.FrontPage> request end
      DEBUG <hotline.pages.FrontPage$LoginForm> request end
      ...
      //form submitted
      DEBUG <hotline.pages.FrontPage> request end
      DEBUG <hotline.pages.FrontPage$LoginForm> request end

        Activity

        Hide
        Paul Milovanov added a comment -

        as expected, this is more general : also getting the same problem when handling a Link.onClick()

        Show
        Paul Milovanov added a comment - as expected, this is more general : also getting the same problem when handling a Link.onClick()
        Hide
        Paul Milovanov added a comment -

        similar behavoir when using 1.2_rc2

        Show
        Paul Milovanov added a comment - similar behavoir when using 1.2_rc2
        Hide
        Paul Milovanov added a comment -

        the problem might be that the default Page.beforeCallComponent() is just {}

        my knowledge of wicket architecture is nil, but so far it seems that after RequestListenerInterface is resolved to IFormSubmitListener (as seems to be the case here), there is just no code which would call Page.internalAttach anywhere

        Show
        Paul Milovanov added a comment - the problem might be that the default Page.beforeCallComponent() is just {} my knowledge of wicket architecture is nil, but so far it seems that after RequestListenerInterface is resolved to IFormSubmitListener (as seems to be the case here), there is just no code which would call Page.internalAttach anywhere
        Hide
        Eelco Hillenius added a comment -

        Tested it and it works fine for current 1.x and 2.0. Don't know when it ever was a problem, but it isn't anymore. Are you sure you didn't override it in some super class (base page?) so that the calls don't get delegated further down the line?

        Please update your version of Wicket and confirm it works you you. thanks.

        Show
        Eelco Hillenius added a comment - Tested it and it works fine for current 1.x and 2.0. Don't know when it ever was a problem, but it isn't anymore. Are you sure you didn't override it in some super class (base page?) so that the calls don't get delegated further down the line? Please update your version of Wicket and confirm it works you you. thanks.
        Hide
        Martin Benda added a comment -

        Hi!

        I have got a similar problem with current 2.0-SNAPSHOT (updated form svn repo before two hours) that may be related to this bug:

        When a Form on page A is submitted and the response page is set to page B (via setResponsePagec(B.class) in the Form#onSubmit() method), the onAttach, onDetach etc. methods of page A are not called - as a consequence, the form model, which was updated (and attached) as a result of form submit, is not detached at the end of the request.

        I have created a simple test case: http://sucker.pilsfree.net/wicket-detach.tar.gz

        – IndexPage entered –
        27.11.2006 10:09:35 com.cleverlance.wicketdetach.IndexPage onAttach
        INFO: onAttach
        27.11.2006 10:09:35 com.cleverlance.wicketdetach.IndexPage onDetach
        INFO: onDetach

        – FormPage entered –
        27.11.2006 10:11:09 com.cleverlance.wicketdetach.FormPage onAttach
        INFO: onAttach
        27.11.2006 10:11:09 com.cleverlance.wicketdetach.SimpleModel detach
        INFO: detaching Model:classname=[com.cleverlance.wicketdetach.SimpleModel]:object=[com.cleverlance.wicketdetach.Data@1f3f16b]
        27.11.2006 10:11:09 com.cleverlance.wicketdetach.SimpleModel detach
        INFO: detaching Model:classname=[com.cleverlance.wicketdetach.SimpleModel]:object=[com.cleverlance.wicketdetach.Data@1f3f16b]
        27.11.2006 10:11:09 com.cleverlance.wicketdetach.SimpleModel detach
        INFO: detaching Model:classname=[com.cleverlance.wicketdetach.SimpleModel]:object=[com.cleverlance.wicketdetach.Data@1f3f16b]
        27.11.2006 10:11:09 com.cleverlance.wicketdetach.FormPage onDetach
        INFO: onDetach

        – "Submit" clicked –
        27.11.2006 10:11:32 com.cleverlance.wicketdetach.FormPage$1 onSubmit
        INFO: form submitted
        27.11.2006 10:11:32 com.cleverlance.wicketdetach.FormPage onAttach
        INFO: onAttach
        27.11.2006 10:11:32 com.cleverlance.wicketdetach.SimpleModel detach
        INFO: detaching Model:classname=[com.cleverlance.wicketdetach.SimpleModel]:object=[com.cleverlance.wicketdetach.Data@1f3f16b]
        27.11.2006 10:11:32 com.cleverlance.wicketdetach.SimpleModel detach
        INFO: detaching Model:classname=[com.cleverlance.wicketdetach.SimpleModel]:object=[com.cleverlance.wicketdetach.Data@1f3f16b]
        27.11.2006 10:11:32 com.cleverlance.wicketdetach.SimpleModel detach
        INFO: detaching Model:classname=[com.cleverlance.wicketdetach.SimpleModel]:object=[com.cleverlance.wicketdetach.Data@1f3f16b]
        27.11.2006 10:11:32 com.cleverlance.wicketdetach.FormPage onDetach
        INFO: onDetach

        – "Submit & Return" clicked –
        27.11.2006 10:11:59 com.cleverlance.wicketdetach.FormPage$1 onSubmit
        INFO: form submitted
        27.11.2006 10:11:59 com.cleverlance.wicketdetach.IndexPage onAttach
        INFO: onAttach
        27.11.2006 10:11:59 com.cleverlance.wicketdetach.IndexPage onDetach
        INFO: onDetach

        Show
        Martin Benda added a comment - Hi! I have got a similar problem with current 2.0-SNAPSHOT (updated form svn repo before two hours) that may be related to this bug: When a Form on page A is submitted and the response page is set to page B (via setResponsePagec(B.class) in the Form#onSubmit() method), the onAttach, onDetach etc. methods of page A are not called - as a consequence, the form model, which was updated (and attached) as a result of form submit, is not detached at the end of the request. I have created a simple test case: http://sucker.pilsfree.net/wicket-detach.tar.gz – IndexPage entered – 27.11.2006 10:09:35 com.cleverlance.wicketdetach.IndexPage onAttach INFO: onAttach 27.11.2006 10:09:35 com.cleverlance.wicketdetach.IndexPage onDetach INFO: onDetach – FormPage entered – 27.11.2006 10:11:09 com.cleverlance.wicketdetach.FormPage onAttach INFO: onAttach 27.11.2006 10:11:09 com.cleverlance.wicketdetach.SimpleModel detach INFO: detaching Model:classname= [com.cleverlance.wicketdetach.SimpleModel] :object= [com.cleverlance.wicketdetach.Data@1f3f16b] 27.11.2006 10:11:09 com.cleverlance.wicketdetach.SimpleModel detach INFO: detaching Model:classname= [com.cleverlance.wicketdetach.SimpleModel] :object= [com.cleverlance.wicketdetach.Data@1f3f16b] 27.11.2006 10:11:09 com.cleverlance.wicketdetach.SimpleModel detach INFO: detaching Model:classname= [com.cleverlance.wicketdetach.SimpleModel] :object= [com.cleverlance.wicketdetach.Data@1f3f16b] 27.11.2006 10:11:09 com.cleverlance.wicketdetach.FormPage onDetach INFO: onDetach – "Submit" clicked – 27.11.2006 10:11:32 com.cleverlance.wicketdetach.FormPage$1 onSubmit INFO: form submitted 27.11.2006 10:11:32 com.cleverlance.wicketdetach.FormPage onAttach INFO: onAttach 27.11.2006 10:11:32 com.cleverlance.wicketdetach.SimpleModel detach INFO: detaching Model:classname= [com.cleverlance.wicketdetach.SimpleModel] :object= [com.cleverlance.wicketdetach.Data@1f3f16b] 27.11.2006 10:11:32 com.cleverlance.wicketdetach.SimpleModel detach INFO: detaching Model:classname= [com.cleverlance.wicketdetach.SimpleModel] :object= [com.cleverlance.wicketdetach.Data@1f3f16b] 27.11.2006 10:11:32 com.cleverlance.wicketdetach.SimpleModel detach INFO: detaching Model:classname= [com.cleverlance.wicketdetach.SimpleModel] :object= [com.cleverlance.wicketdetach.Data@1f3f16b] 27.11.2006 10:11:32 com.cleverlance.wicketdetach.FormPage onDetach INFO: onDetach – "Submit & Return" clicked – 27.11.2006 10:11:59 com.cleverlance.wicketdetach.FormPage$1 onSubmit INFO: form submitted 27.11.2006 10:11:59 com.cleverlance.wicketdetach.IndexPage onAttach INFO: onAttach 27.11.2006 10:11:59 com.cleverlance.wicketdetach.IndexPage onDetach INFO: onDetach
        Hide
        Eelco Hillenius added a comment -

        got another use case is seems

        Show
        Eelco Hillenius added a comment - got another use case is seems
        Hide
        Johan Compagner added a comment -

        as far as i know it was always this:

        onBeginRequest -> only in the render phase not in request phase
        onEndRequest -> after render phase.

        And then we have onComponentCalled (or what every it is called that was between the interface/request call.

        is page.onBeginRequest not called before the listener interface? (form.onsubmit)?
        What is exactly the fix?

        Show
        Johan Compagner added a comment - as far as i know it was always this: onBeginRequest -> only in the render phase not in request phase onEndRequest -> after render phase. And then we have onComponentCalled (or what every it is called that was between the interface/request call. is page.onBeginRequest not called before the listener interface? (form.onsubmit)? What is exactly the fix?
        Hide
        Eelco Hillenius added a comment -

        Johan, can I assign this to you?

        Show
        Eelco Hillenius added a comment - Johan, can I assign this to you?
        Hide
        Igor Vaynberg added a comment -

        in the end i do not think we are going to support this because there is no good way to do it.
        onattach will be called before render and while the hieararchy can still be modified - like it is now
        we were talking about dropping beforerender and renaming onattach to beforerender - because that is what it really is

        Show
        Igor Vaynberg added a comment - in the end i do not think we are going to support this because there is no good way to do it. onattach will be called before render and while the hieararchy can still be modified - like it is now we were talking about dropping beforerender and renaming onattach to beforerender - because that is what it really is
        Hide
        Eelco Hillenius added a comment -

        So Johan, feel free to close it if you agree.

        Show
        Eelco Hillenius added a comment - So Johan, feel free to close it if you agree.
        Hide
        Johan Compagner added a comment -

        yes onAttach() and onBeforeRender is now purely for the render phase

        onDetach() is called always so that models and components are detached correctly.
        And detach() must be called even if (the current) attach is not called because of that.

        So when you submit a form and then respond/render to another page
        the onAttach is not called for that page with that form. But detach is..

        I think this is wrong and i already have said i think on the user list how it should be: (last night i really needed that onattach anyway that i now have found through IPageEntry...)

        on submit request comes in respond to same page:

        Page.onAttach();
        form.onSubmit();
        Page.onBeginRender();
        Page.render();
        Page.onEndRender();
        Page.onDetach();

        on submit request comes in respond to another page:

        Page1.onAttach();
        form.onSubmit();
        Page2.onAttach();
        Page2.onBeginRender();
        Page2.render();
        Page2.onEndRender();
        Page2.onDetach();
        Page.1onDetach();

        Show
        Johan Compagner added a comment - yes onAttach() and onBeforeRender is now purely for the render phase onDetach() is called always so that models and components are detached correctly. And detach() must be called even if (the current) attach is not called because of that. So when you submit a form and then respond/render to another page the onAttach is not called for that page with that form. But detach is.. I think this is wrong and i already have said i think on the user list how it should be: (last night i really needed that onattach anyway that i now have found through IPageEntry...) on submit request comes in respond to same page: Page.onAttach(); form.onSubmit(); Page.onBeginRender(); Page.render(); Page.onEndRender(); Page.onDetach(); on submit request comes in respond to another page: Page1.onAttach(); form.onSubmit(); Page2.onAttach(); Page2.onBeginRender(); Page2.render(); Page2.onEndRender(); Page2.onDetach(); Page.1onDetach();
        Hide
        Igor Vaynberg added a comment -

        yes yes, but can we do it for 2.0? this is a pretty big break in concept. first we have to remove onbeginrender() then rename any onattach to onbeginrender() and then create the new onattach(). this means all users have to do the same in their code! not only that they also need to know to use onbeginrender() instead of onattach() now.

        i dont mind doing it in my 2.0 projects, but what about others?

        also we need to lock the hierarachy in onattach(), no point in letting someone remove a component whose listener is about to get invoked.

        Show
        Igor Vaynberg added a comment - yes yes, but can we do it for 2.0? this is a pretty big break in concept. first we have to remove onbeginrender() then rename any onattach to onbeginrender() and then create the new onattach(). this means all users have to do the same in their code! not only that they also need to know to use onbeginrender() instead of onattach() now. i dont mind doing it in my 2.0 projects, but what about others? also we need to lock the hierarachy in onattach(), no point in letting someone remove a component whose listener is about to get invoked.
        Hide
        Johan Compagner added a comment -

        can't we do it a bit different with a bit different names?
        and the depricate and make the make the current methods final?

        We could also just keep the current onBeginRender things (they are pretty much in the right place already so whats done there is fine)
        and make onAttach final and call it a bit different?

        Show
        Johan Compagner added a comment - can't we do it a bit different with a bit different names? and the depricate and make the make the current methods final? We could also just keep the current onBeginRender things (they are pretty much in the right place already so whats done there is fine) and make onAttach final and call it a bit different?
        Hide
        Igor Vaynberg added a comment -

        what would you call onattach() ? i mean we can just deprecate onattach() and call it from inside onbeginrender()
        but onattach is such a good name! and then what? after 2.0 you rename it back or will we be stuck with this new name forever?

        Show
        Igor Vaynberg added a comment - what would you call onattach() ? i mean we can just deprecate onattach() and call it from inside onbeginrender() but onattach is such a good name! and then what? after 2.0 you rename it back or will we be stuck with this new name forever?
        Hide
        Johan Compagner added a comment -

        attach()/detach() ?
        so drop the on? (i know the rest are on....)

        Show
        Johan Compagner added a comment - attach()/detach() ? so drop the on? (i know the rest are on....)
        Hide
        Igor Vaynberg added a comment -

        no that would be horrible. besides we already have attach()/detach() that encapsulate the super-called check.

        maybe all we do is this

        mark onattach as final and tell people to move to onbeginrender

        let that break sit in there for a few weeks to give people a chance to migrate, then go back in and rework onattach

        Show
        Igor Vaynberg added a comment - no that would be horrible. besides we already have attach()/detach() that encapsulate the super-called check. maybe all we do is this mark onattach as final and tell people to move to onbeginrender let that break sit in there for a few weeks to give people a chance to migrate, then go back in and rework onattach
        Hide
        Johan Compagner added a comment -

        but for how long?
        in 1.3 or 2.0?

        Because anybody that didn't move in that period but after that has a problem.

        onBeginRequest/onEndRequest?

        onBegin/onEnd

        onRequest/on????

        onUse/onNotUsedAnyMoreUntilUsedAgain

        why do we have onAttach and attach()? wasn't it the point that we don't need 2 of those?
        and when is attach() now called?

        Show
        Johan Compagner added a comment - but for how long? in 1.3 or 2.0? Because anybody that didn't move in that period but after that has a problem. onBeginRequest/onEndRequest? onBegin/onEnd onRequest/on???? onUse/onNotUsedAnyMoreUntilUsedAgain why do we have onAttach and attach()? wasn't it the point that we don't need 2 of those? and when is attach() now called?
        Hide
        Igor Vaynberg added a comment -

        onAttach() is the listener - you put your code into it and it is invoked at some point for you
        attach() is used by the framework to do what it needs to attach the component - which includes invoking the onAttach()
        attach() is public final, if java had a better permission system this method would not be visible to users

        as far as i know these changes would only be for 2.0

        Show
        Igor Vaynberg added a comment - onAttach() is the listener - you put your code into it and it is invoked at some point for you attach() is used by the framework to do what it needs to attach the component - which includes invoking the onAttach() attach() is public final, if java had a better permission system this method would not be visible to users as far as i know these changes would only be for 2.0
        Hide
        Johan Compagner added a comment -

        this is all fixed now

        Show
        Johan Compagner added a comment - this is all fixed now

          People

          • Assignee:
            Johan Compagner
            Reporter:
            Paul Milovanov
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development