Quantcast

Calling setResponsePage during Ajax submit

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Calling setResponsePage during Ajax submit

gmparker2000
I have the following situation:

- ajax button clicked
- request cycle begins
- the button's onSubmit method is called
- onSubmit method calls setResponsePage
- request cycle continues, components are initialized, etc
- request cycle ends with a response that contains an ajax-response redirect
- browser redirects to the page
- new request cycle begins, the same components are initialized again, etc.

So it looks like the entire page hierarchy is being initialized during the ajax onSubmit request cycle, thrown away and then reconstructed during the next request cycle.  I'm guessing I'm doing something wrong.  Hopefully someone can shed some light on this for me.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling setResponsePage during Ajax submit

Sven Meier
Hi,

your situation looks pretty normal.

What do you mean by "are initialized (again)" - #onInitialize() is
called again?

What argument do you pass to #setResponsePage() ?

Have fun
Sven


On 17.02.2017 02:47, gmparker2000 wrote:

> I have the following situation:
>
> - ajax button clicked
> - request cycle begins
> - the button's onSubmit method is called
> - onSubmit method calls setResponsePage
> - request cycle continues, *components are initialized*, etc
> - request cycle ends with a response that contains an ajax-response redirect
> - browser redirects to the page
> - new request cycle begins, *the same components are initialized again*,
> etc.
>
> So it looks like the entire page hierarchy is being initialized during the
> ajax onSubmit request cycle, thrown away and then reconstructed during the
> next request cycle.  I'm guessing I'm doing something wrong.  Hopefully
> someone can shed some light on this for me.
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Calling-setResponsePage-during-Ajax-submit-tp4677132.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling setResponsePage during Ajax submit

gmparker2000
Let me try to elaborate a bit more with some pseudo code:

PageOne {
  onInitialize() {
     AjaxButton b = new AjaxButton(...) {
         onSubmit() {
            ...
            setResponsePage(PageB)
         }
     }

     // initialize components for page one
     TextField t = new TextField(...)
     add(t)
     ...
  }
}

PageTwo {
  onInitialize() {
    // initialize components for page two
    ...
  }
}

So what I see is that when the onSubmit method of page one is called, wicket continues to call the onInitialize of page one even though page one will not be displayed again as I've set the response page to page two.  So TextField 't' is created even though it will never be rendered.  After the Ajax request  that triggers the onSubmit on page one, a response is sent back with a redirect to page two.  The browser redirects and page two is initialized and sent back in the response.  It appears as though page one is being initialized a second time (after the Ajax button submit) unnecessarily in my situation.  I've verified this to be the case by tracing through the initialization processing.  Maybe this is normal, but I'm hoping not.  Some of the pages I am dealing with are quite large and require a lot of initialization that I don't care to do twice.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling setResponsePage during Ajax submit

Martin Grigorov-4
On Fri, Feb 17, 2017 at 1:32 PM, gmparker2000 <[hidden email]>
wrote:

> Let me try to elaborate a bit more with some pseudo code:
>
> PageOne {
>   onInitialize() {
>      AjaxButton b = new AjaxButton(...) {
>          onSubmit() {
>             ...
>             setResponsePage(PageB)
>

Is this PageB.class or pageBInstance ?


>          }

     }

>
>      // initialize components for page one
>      TextField t = new TextField(...)
>      add(t)
>      ...
>   }
> }
>
> PageTwo {
>   onInitialize() {
>     // initialize components for page two
>     ...
>   }
> }
>
> So what I see is that when the onSubmit method of page one is called,
> wicket
> continues to call the onInitialize of page one even though page one will
> not
> be displayed again as I've set the response page to page two.  So TextField
> 't' is created even though it will never be rendered.  After the Ajax
> request  that triggers the onSubmit on page one, a response is sent back
> with a redirect to page two.  The browser redirects and page two is
> initialized and sent back in the response.  It appears as though page one
> is
> being initialized a second time (after the Ajax button submit)
> unnecessarily
> in my situation.  I've verified this to be the case by tracing through the
> initialization processing.  Maybe this is normal, but I'm hoping not.  Some
> of the pages I am dealing with are quite large and require a lot of
> initialization that I don't care to do twice.
>
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/Calling-setResponsePage-during-Ajax-
> submit-tp4677132p4677135.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling setResponsePage during Ajax submit

gmparker2000
It's an instance.  Specifically in my case it looks like this:

this.setResponsePage(new FormsPage());
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling setResponsePage during Ajax submit

gmparker2000
Further clarification after digging deeper.  Looks like it's the onBeforeRender method that is getting called twice for page a.  I think I may have oversimplified the example.  Does it make sense, given the situation I explained, that onBeforeRender would be called twice for page a?  We are doing a lot of initialization in onBeforeRender because of our particular use case.  Is this bad practice?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling setResponsePage during Ajax submit

Martin Grigorov-4
In reply to this post by gmparker2000
On Fri, Feb 17, 2017 at 1:56 PM, gmparker2000 <[hidden email]>
wrote:

> It's an instance.  Specifically in my case it looks like this:
>
> this.setResponsePage(new FormsPage());
>

In this case the code in the constructor will be executed in the first
request and the code in onInitialize() in the second request.

setResponsePage() just schedules rendering of a page (instance).
If you want Wicket to not proceed then you need to throw
RestartResponseException(page[Class])


>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/Calling-setResponsePage-during-Ajax-
> submit-tp4677132p4677137.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Calling setResponsePage during Ajax submit

Martin Grigorov-4
On Fri, Feb 17, 2017 at 2:23 PM, Martin Grigorov <[hidden email]>
wrote:

>
> On Fri, Feb 17, 2017 at 1:56 PM, gmparker2000 <[hidden email]>
> wrote:
>
>> It's an instance.  Specifically in my case it looks like this:
>>
>> this.setResponsePage(new FormsPage());
>>
>
> In this case the code in the constructor will be executed in the first
> request and the code in onInitialize() in the second request.
>

Actually this is not correct.
onInitialize(), onConfigure(), all render methods will be executed in the
first request.
Wicket will store the html and make a redirect (in case of
REDIRECT_TO_BUFFER).

If you use REDIRECT_TO_RENDER then those will be executed in the second
request.

With RestartResponseException you have more control with its RedirectPolicy
parameter.


>
> setResponsePage() just schedules rendering of a page (instance).
> If you want Wicket to not proceed then you need to throw
> RestartResponseException(page[Class])
>
>
>>
>> --
>> View this message in context: http://apache-wicket.1842946.n
>> 4.nabble.com/Calling-setResponsePage-during-Ajax-submit-
>> tp4677132p4677137.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
Loading...