You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by lovewicket <pe...@hotmail.com> on 2011/03/25 21:06:11 UTC

StatelessForm redirect

Hello, 

I built a stateless website using Bookmarkable pages and links. I have a
base page with a search form (StatelessForm) which all the other pages
(bookmarkable) extend to share this form and some other tabs (Home, Links,
etc). My problem is that if this search box is on AbcPage or XyzPage, on
submit the pageparameters are forwarded to AbcPage first and then redirected
to SearchResultsPage. But, since pageparameters validation fails on
AbcPage/XyzPage, I get an exception and the further redirect gives an error
too. Is there a way to go straight to SearchResultsPage without going
through the current AbcPage? I am using latest wicket distribution
(apache-wicket-1.4.16). I have been trying to figure out this for days, so I
would really appreciate any help! 

HTML --- 

  Search:
  
  
  Advanced Search


Java --- 
final StatelessForm form = new StatelessForm("Search", new
CompoundPropertyModel(fSearch)) 
{ 
    @Override 
    protected void onSubmit() 
    { 
        if(sLogger.isInfoEnabled()) 
        { 
            sLogger.info(fSearch.toString()); 
        } 
        setResponsePage(SearchResultsPage.class,
fSearch.toPageParameters()); 
        //setRedirect(false); 
    } 
}; 
// Add the search box to the form 
form.add(new TextField("SearchValue")); 
form.add(new BookmarkablePageLink("advancedSearch",
AdvancedSearchPage.class)); 
        
fParentComponent.add(form); 

Webpage ERROR: 
HTTP Status 404 - 
type Status report 
message 
description The requested resource () is not available. 

Server ERROR: 

2011-03-25 12:53:51.0349 ERROR http-8080-3 index.AbcPage - Exception 
java.lang.NullPointerException 
        at index.AbcPage.validateParams(AbcPage.java:258) 
        at index.AbcPage.(AbcPage.java:86) 
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) 
        at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
        at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 

        at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
        at
org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:188) 
        at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:89) 
        at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:306) 
        at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:321) 
        at
org.apache.wicket.request.target.component.BookmarkableListenerInterfaceRequestTarget.processEvents(BookmarkableListenerInterfaceRequestTarget.java:126)
        at
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92) 
        at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1241) 
        at org.apache.wicket.RequestCycle.step(RequestCycle.java:1320) 
        at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1419) 
        at org.apache.wicket.RequestCycle.request(RequestCycle.java:545) 

I tried mounting the page and supplying the url in action attribute but that
didn't work either. 

Thank you!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3406282.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StatelessForm redirect

Posted by lovewicket <pe...@hotmail.com>.
Thank you so much. That worked! It didn't create a session and the request
went straight to the SearchResultspage.

I'm still not sure why StatelessForm didn't work... but this solution worked
fine for me.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3419629.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StatelessForm redirect

Posted by Clint Checketts <ch...@gmail.com>.
The remaining stack trace seems strange. But ignoring that and focusing on
setting the 'action' attribute, in the webmarkup container that you use (in
stead of a form component)

Do something like:

@Override
onComponentTag(...){
  tag.put("action",RequestCycle.get().urlFor(SearchResultspage.class))
}

Its hacky but would work. Probably want to make sure you've using
method="get" on the form too.

-Clint

On Tue, Mar 29, 2011 at 11:50 AM, lovewicket <pe...@hotmail.com> wrote:

> Actually I handled the exception (in the catch block) and that's how I knew
> that the current page wanted to redirect to the intended page. I was
> getting
> the above posted exception and then the following exception:
>
> 2011-03-28 22:55:49.0783 ERROR http-8080-1
> org.apache.wicket.protocol.http.WebResponse - Unable to redirect to:
>
> searchresults?value=2222&year=All&moviesIncluded=false&imagesIncluded=false&imageType=All&movieType=All&movieSize=Any,
> HTTP Response has already been committed.
> 2011-03-28 22:55:49.0783 ERROR http-8080-1
> org.apache.wicket.protocol.http.WicketFilter - closing the buffer error
> java.lang.IllegalStateException
>        at
>
> org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
>        at
>
> org.apache.wicket.protocol.http.WebResponse.sendRedirect(WebResponse.java:299)
>        at
> org.apache.wicket.protocol.http.WebResponse.redirect(WebResponse.java:250)
>        at
>
> org.apache.wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:67)
>        at
> org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:502)
>        at
>
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
>        at
>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>        at
>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>
> How would you pass in pageparameters through component tag?
>
> Thank you
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3415450.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: StatelessForm redirect

Posted by lovewicket <pe...@hotmail.com>.
Actually I handled the exception (in the catch block) and that's how I knew
that the current page wanted to redirect to the intended page. I was getting
the above posted exception and then the following exception:

2011-03-28 22:55:49.0783 ERROR http-8080-1
org.apache.wicket.protocol.http.WebResponse - Unable to redirect to:
searchresults?value=2222&year=All&moviesIncluded=false&imagesIncluded=false&imageType=All&movieType=All&movieSize=Any,
HTTP Response has already been committed.
2011-03-28 22:55:49.0783 ERROR http-8080-1
org.apache.wicket.protocol.http.WicketFilter - closing the buffer error
java.lang.IllegalStateException
	at
org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
	at
org.apache.wicket.protocol.http.WebResponse.sendRedirect(WebResponse.java:299)
	at
org.apache.wicket.protocol.http.WebResponse.redirect(WebResponse.java:250)
	at
org.apache.wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:67)
	at
org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:502)
	at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

How would you pass in pageparameters through component tag?

Thank you


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3415450.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StatelessForm redirect

Posted by Clint Checketts <ch...@gmail.com>.
Ah, the trouble is in your NPE:

java.lang.NullPointerException
       at index.AbcPage.validateParams(
AbcPage.java:258)

As long as that exception remains unhandled, the pages won't hand off. The
Form has to resubmit back to the page the form lives on since that is where
the form listener is waiting.

If you feel confident and wish to totally bypass wicket's form processing,
instead of a Form you could use a WebMarkupContainer and in the
onComponentTag set the Action attribute to the page you want to redirect to.
I did something similar long ago when I was first learning Wicket. I don't
recommend it, but it is a possible solution.

-Clint

On Mon, Mar 28, 2011 at 10:01 PM, lovewicket <pe...@hotmail.com> wrote:

> I tried to put the following in my application class, but unfortunately got
> the same results (application tries to load the current page and then
> redirect the request):
>
>
> getRequestCycleSettings().setRenderStrategy(IRequestCycleSettings.ONE_PASS_RENDER);
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3413610.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: StatelessForm redirect

Posted by lovewicket <pe...@hotmail.com>.
I tried to put the following in my application class, but unfortunately got
the same results (application tries to load the current page and then
redirect the request):

getRequestCycleSettings().setRenderStrategy(IRequestCycleSettings.ONE_PASS_RENDER);


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3413610.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StatelessForm redirect

Posted by Clint Checketts <ch...@gmail.com>.
Wicket uses a 2 step render :
http://wicket.apache.org/apidocs/1.4/org/apache/wicket/settings/IRequestCycleSettings.html

Have you tried using setRenderStrategy(ONE_PASS_RENDER ONE_PASS_RENDER) in
your application?

-Clint


On Mon, Mar 28, 2011 at 7:37 PM, lovewicket <pe...@hotmail.com> wrote:

> Yes. I have the following in my application class:
>
> mount(new QueryStringUrlCodingStrategy("/searchresults",
> SearchResultsPage.class));
>
> It didn't work. I am not sure why wicket doesn't directly go to the
> specified page instead of loading the current page again and then going to
> the specified page. I would assume, in a stateless environment, this would
> fail everytime. By the way, if I change StatelessForm to Form, it all
> works,
> but it creates a session which is not desired (since we were having memory
> issues with sessions).
>
> As a workaround, I stored the parameters as a hidden field on the page (can
> verify this via Page Source), but when I tried to retrieve them via
> getMarkupAttributes() it came out blank so I have to assume that the
> attributes are added at the last rendering stage and are not read back in
> on
> form submit.
>
> I would really appreciate any ideas. Thanks.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3413429.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: StatelessForm redirect

Posted by lovewicket <pe...@hotmail.com>.
Yes. I have the following in my application class:

mount(new QueryStringUrlCodingStrategy("/searchresults",
SearchResultsPage.class));

It didn't work. I am not sure why wicket doesn't directly go to the
specified page instead of loading the current page again and then going to
the specified page. I would assume, in a stateless environment, this would
fail everytime. By the way, if I change StatelessForm to Form, it all works,
but it creates a session which is not desired (since we were having memory
issues with sessions).

As a workaround, I stored the parameters as a hidden field on the page (can
verify this via Page Source), but when I tried to retrieve them via
getMarkupAttributes() it came out blank so I have to assume that the
attributes are added at the last rendering stage and are not read back in on
form submit.

I would really appreciate any ideas. Thanks.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3413429.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StatelessForm redirect

Posted by Clint Checketts <ch...@gmail.com>.
Do you get the same error when mounting the page using a
QueryStringEncodingStrategy?

On Monday, March 28, 2011, lovewicket <pe...@hotmail.com> wrote:
> It looks like onSubmit, request first comes to the current page and then it
> gets forwarded to the results page. I am not sure why this is the case. In
> stateless application, loading the current page again fails the validation
> because the parameters that are needed to build the current page are not
> there. I even tried to store these as a hidden field, but on form submit
> they come up blank.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3412643.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StatelessForm redirect

Posted by lovewicket <pe...@hotmail.com>.
It looks like onSubmit, request first comes to the current page and then it
gets forwarded to the results page. I am not sure why this is the case. In
stateless application, loading the current page again fails the validation
because the parameters that are needed to build the current page are not
there. I even tried to store these as a hidden field, but on form submit
they come up blank.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/StatelessForm-redirect-tp3406282p3412643.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org