Re: Form submit and nice urls
How about something like the following. It's not pretty but it works in Wicket 1.5 and my submitted form ends up being .../target-page?input1=value1input2=value2... with no redirects. HTML: form method=get wicket:id=form ... inputs here ... /form Java: final CharSequence url = RequestCycle.get().urlFor(TargetPage.class, null); final Form f = new Form(form) { // TODO: there may be thread safety issues here - not sure boolean inComponentTagBody = false; @Override public boolean isRootForm() { if (inComponentTagBody) return false; return super.isRootForm(); } @Override public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { inComponentTagBody = true; super.onComponentTagBody(markupStream, openTag); inComponentTagBody = false; } }; f.add(new AttributeModifier(action, true, new Model(url.toString(; add(f); -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Form-submit-and-nice-urls-tp3521053p3641551.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form submit and nice urls
Anybody? Hi, when I'm doing [1] in 1.4.17 in a quickstart then I'm getting nice urls ala ?q=something e.g. for typing something in the textfield. The problem is that it prints two GET requests (why not POST + GET?): NOW: q = [todo] query=todo GET NOW: query=null GET In firebug I can see POST + GET: POST http://localhost:8080/wicket1.4.17/?wicket:interface=:0:searchform::IFormSubmitListener:: GET http://localhost:8080/wicket1.4.17/?q=test How can I avoid the second call of HomePage with query=null?? When I do setRedirect(false) after setResponsePage I don't get the nice url but it prints only one POST request with the correct parameter: NOW: q = test query=test POST Finally I tried to explicitely set the form method to GET: @Override protected String getMethod() { return METHOD_GET; } but then I would need to declare every url parameter as hidden field or can I somehow overwrite the form action with my need parameters? About a similar problem was blogged here [2] Could someone enlight me whats going wrong here? Regards, Peter. [1] public HomePage(final PageParameters parameters) { Form form = new Form(searchform) { @Override protected void onSubmit() { PageParameters pp = new PageParameters(); pp.add(q, query); // add other params from previous request setResponsePage(HomePage.class, pp); } }; add(form); query = parameters.getString(q); TextField text = new TextField(textField, new PropertyModel(this, query)); form.add(text); logger.info(NOW: + parameters + query= + query + + getMethod()); } public String getMethod() { return ((WebRequest) getRequest()).getHttpServletRequest().getMethod(); } [2] http://blog.solidcraft.eu/2010/10/wicket-form-submit-not-safe-for.html - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form submit and nice urls
Hi Peter, Here is how it should work: - Home page constructor is called initially without 'q' thus null - the submit makes a POST call to Form.onSubmit() (the print is not called because the page is not re-instanciated, unless it is stateless) - onSubmit() calls setResponsePage(Class, PageParameters) which causes a redirect to the Home page with the parameters you pass - HomePage's ctor is called with 'q' and a value This is how it should be! Now you take a look and tell us where are the differences. On Mon, May 16, 2011 at 12:41 PM, Peter Karich peat...@yahoo.de wrote: Anybody? Hi, when I'm doing [1] in 1.4.17 in a quickstart then I'm getting nice urls ala ?q=something e.g. for typing something in the textfield. The problem is that it prints two GET requests (why not POST + GET?): NOW: q = [todo] query=todo GET NOW: query=null GET In firebug I can see POST + GET: POST http://localhost:8080/wicket1.4.17/?wicket:interface=:0:searchform::IFormSubmitListener :: GET http://localhost:8080/wicket1.4.17/?q=test How can I avoid the second call of HomePage with query=null?? When I do setRedirect(false) after setResponsePage I don't get the nice url but it prints only one POST request with the correct parameter: NOW: q = test query=test POST Finally I tried to explicitely set the form method to GET: @Override protected String getMethod() { return METHOD_GET; } but then I would need to declare every url parameter as hidden field or can I somehow overwrite the form action with my need parameters? About a similar problem was blogged here [2] Could someone enlight me whats going wrong here? Regards, Peter. [1] public HomePage(final PageParameters parameters) { Form form = new Form(searchform) { @Override protected void onSubmit() { PageParameters pp = new PageParameters(); pp.add(q, query); // add other params from previous request setResponsePage(HomePage.class, pp); } }; add(form); query = parameters.getString(q); TextField text = new TextField(textField, new PropertyModel(this, query)); form.add(text); logger.info(NOW: + parameters + query= + query + + getMethod()); } public String getMethod() { return ((WebRequest) getRequest()).getHttpServletRequest().getMethod(); } [2] http://blog.solidcraft.eu/2010/10/wicket-form-submit-not-safe-for.html - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com http://jweekend.com/
Re: Form submit and nice urls
Hi Martin, thanks for the explanation! Why is the first call done to submit my form? Because my app is doing an 'expensive' search query for every instantiation, thus I would like to trigger the search only with the necessary submitted query. Can I somehow distinguish a request with an empty q and the pre-query with an empty q when submitting a form? Or should I place my expensive operation somewhere else? Regards, Peter. Hi Peter, Here is how it should work: - Home page constructor is called initially without 'q' thus null - the submit makes a POST call to Form.onSubmit() (the print is not called because the page is not re-instanciated, unless it is stateless) - onSubmit() calls setResponsePage(Class, PageParameters) which causes a redirect to the Home page with the parameters you pass - HomePage's ctor is called with 'q' and a value This is how it should be! Now you take a look and tell us where are the differences. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form submit and nice urls
I don't understand your question. with the current code doing the POST is quite cheap. it just brings the value for the search to form#onSubmit and makes a redirect to HomePage(PageParameters) where you check for the existence of the 'q' parameter and either do the heavy calculation or not. You may also check StatelessForm and see whether it fits your needs. It will save you the redirect. Otherwise you can do the calculation in form#onsubmit and use setResponsePage(new HomePage(calculationResult)) - the con here is that the url will have ?wicket:interface=. and wont be nice looking. On Mon, May 16, 2011 at 1:34 PM, Peter Karich peat...@yahoo.de wrote: Hi Martin, thanks for the explanation! Why is the first call done to submit my form? Because my app is doing an 'expensive' search query for every instantiation, thus I would like to trigger the search only with the necessary submitted query. Can I somehow distinguish a request with an empty q and the pre-query with an empty q when submitting a form? Or should I place my expensive operation somewhere else? Regards, Peter. Hi Peter, Here is how it should work: - Home page constructor is called initially without 'q' thus null - the submit makes a POST call to Form.onSubmit() (the print is not called because the page is not re-instanciated, unless it is stateless) - onSubmit() calls setResponsePage(Class, PageParameters) which causes a redirect to the Home page with the parameters you pass - HomePage's ctor is called with 'q' and a value This is how it should be! Now you take a look and tell us where are the differences. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com http://jweekend.com/
Re: Form submit and nice urls
Hi Martin, I don't understand your question. sorry :( I try to explain it again :) When I access my app with the url http://localhost:8080/app/?q=test all is fine. But when I submit a new query 'todo' then wicket somehow 1. calls the submit (ok) 2. redirects to HomePage (ok) 3. *but then again wicket is doing*** another POST+GET with empty q So 4 requests for one submit. Please also try this quickstart for wicket 1.4.17: https://gist.github.com/974349 and see if you get the same problem. Regards, Peter. ** post: onSubmit textField object:todo GET: HomePage ctor params: q = [todo] post: onSubmit textField object: GET: HomePage ctor params: q = []
Re: Form submit and nice urls
Please create a quickstart app (.zip, .tgz) and attach it to a ticket in our Jira. On Mon, May 16, 2011 at 2:33 PM, Peter Karich peat...@yahoo.de wrote: Hi Martin, I don't understand your question. sorry :( I try to explain it again :) When I access my app with the url http://localhost:8080/app/?q=test all is fine. But when I submit a new query 'todo' then wicket somehow 1. calls the submit (ok) 2. redirects to HomePage (ok) 3. *but then again wicket is doing*** another POST+GET with empty q So 4 requests for one submit. Please also try this quickstart for wicket 1.4.17: https://gist.github.com/974349 and see if you get the same problem. Regards, Peter. ** post: onSubmit textField object:todo GET: HomePage ctor params: q = [todo] post: onSubmit textField object: GET: HomePage ctor params: q = [] -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com http://jweekend.com/
Re: Form submit and nice urls
Hopefully I do not waste your time with my stupidity: https://issues.apache.org/jira/browse/WICKET-3720 https://issues.apache.org/jira/secure/attachment/12479325/double-form-submit.zip Please create a quickstart app (.zip, .tgz) and attach it to a ticket in our Jira. On Mon, May 16, 2011 at 2:33 PM, Peter Karich peat...@yahoo.de wrote: Hi Martin, I don't understand your question. sorry :( I try to explain it again :) When I access my app with the url http://localhost:8080/app/?q=test all is fine. But when I submit a new query 'todo' then wicket somehow 1. calls the submit (ok) 2. redirects to HomePage (ok) 3. *but then again wicket is doing*** another POST+GET with empty q So 4 requests for one submit. Please also try this quickstart for wicket 1.4.17: https://gist.github.com/974349 and see if you get the same problem. Regards, Peter. ** post: onSubmit textField object:todo GET: HomePage ctor params: q = [todo] post: onSubmit textField object: GET: HomePage ctor params: q = [] - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Form submit and nice urls
Hi, when I'm doing [1] in 1.4.17 in a quickstart then I'm getting nice urls ala ?q=something e.g. for typing something in the textfield. The problem is that it prints two GET requests (why not POST + GET?): NOW: q = [todo] query=todo GET NOW: query=null GET In firebug I can see POST + GET: POST http://localhost:8080/wicket1.4.17/?wicket:interface=:0:searchform::IFormSubmitListener:: GET http://localhost:8080/wicket1.4.17/?q=test How can I avoid the second call of HomePage with query=null?? When I do setRedirect(false) after setResponsePage I don't get the nice url but it prints only one POST request with the correct parameter: NOW: q = test query=test POST Finally I tried to explicitely set the form method to GET: @Override protected String getMethod() { return METHOD_GET; } but then I would need to declare every url parameter as hidden field or can I somehow overwrite the form action with my need parameters? About a similar problem was blogged here [2] Could someone enlight me whats going wrong here? Regards, Peter. [1] public HomePage(final PageParameters parameters) { Form form = new Form(searchform) { @Override protected void onSubmit() { PageParameters pp = new PageParameters(); pp.add(q, query); // add other params from previous request setResponsePage(HomePage.class, pp); } }; add(form); query = parameters.getString(q); TextField text = new TextField(textField, new PropertyModel(this, query)); form.add(text); logger.info(NOW: + parameters + query= + query + + getMethod()); } public String getMethod() { return ((WebRequest) getRequest()).getHttpServletRequest().getMethod(); } [2] http://blog.solidcraft.eu/2010/10/wicket-form-submit-not-safe-for.html - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Form submit and nice urls
Hi, when I'm doing [1] in 1.4.17 in a quickstart then I'm getting nice urls ala ?q=something e.g. for typing something in the textfield. The problem is that it prints two GET requests (why not POST + GET?): NOW: q = [todo] query=todo GET NOW: query=null GET In firebug I can see POST + GET: POST http://localhost:8080/wicket1.4.17/?wicket:interface=:0:searchform::IFormSubmitListener:: GET http://localhost:8080/wicket1.4.17/?q=test How can I avoid the second call of HomePage with query=null?? When I do setRedirect(false) after setResponsePage I don't get the nice url but it prints only one POST request with the correct parameter: NOW: q = test query=test POST Finally I tried to explicitely set the form method to GET: @Override protected String getMethod() { return METHOD_GET; } but then I would need to declare every url parameter as hidden field or can I somehow overwrite the form action with my need parameters? About a similar problem was blogged here [2] Could someone enlight me whats going wrong here? Regards, Peter. [1] public HomePage(final PageParameters parameters) { Form form = new Form(searchform) { @Override protected void onSubmit() { PageParameters pp = new PageParameters(); pp.add(q, query); // add other params from previous request setResponsePage(HomePage.class, pp); } }; add(form); query = parameters.getString(q); TextField text = new TextField(textField, new PropertyModel(this, query)); form.add(text); logger.info(NOW: + parameters + query= + query + + getMethod()); } public String getMethod() { return ((WebRequest) getRequest()).getHttpServletRequest().getMethod(); } [2] http://blog.solidcraft.eu/2010/10/wicket-form-submit-not-safe-for.html - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org