Re: Clearing form errors problem
I had a related problem. An Ajax form submit stopped working after the page returned a StreamResponse. Manually refreshing the page fixed it, which provided the clue to a better fix. (Aided by this list -- there were a couple of posts on 9/4 and 9/24 about it... maybe this is corrected in a later version of Tapestry.) Here's the fix I added to my StreamReponse class. It works for me but you'll see the limitations. public class MyStreamResponse implements StreamResponse { public void prepareResponse(Response response) { response.setHeader("Expires", "0"); //... other header settings... // Tell the browser to refresh soon after the stream is delivered, // with this Refresh header. It isn't a perfect fix because it doesn't take effect // if the user clicks Cancel on the file-download dialog (if the user doesn't allow // automatic file opening). // // The refresh will cause the user's form inputs to be lost. // Hence I've made the form values page-persistent in pages using this. *response.setHeader("Refresh", "1");* //... } } On Thu, Nov 10, 2011 at 8:48 PM, Steve Eynon wrote: > Sounds like you want a StreamResponse to be returned AND and a page > refresh at the same time - unfortunately HTTP doesn't allow this. > > A technique would be return the page, then re-direct the user to a > different page / event link which returns the CSV. > > It's also discussed in this thread: > > http://tapestry.1045711.n5.nabble.com/StreamResponse-on-Success-td2434690.html#a2434692 > > Steve. > > > On 10 November 2011 19:08, goldenka wrote: > > I have something linke: > > > > > t:format="dd/MM/" t:type="DateField" validate="required" /> > > > > > > and validation is server-side (onValidateForm() method) so I think i must > > use JavaScript. Can you provide me some simple solution ? I think I must > > remove some div's, but don't know how to do this... > > > > -- > > View this message in context: > http://tapestry.1045711.n5.nabble.com/Clearing-form-errors-problem-tp4971307p4980738.html > > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > > - > > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > > For additional commands, e-mail: users-h...@tapestry.apache.org > > > > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >
Re: Clearing form errors problem
Sounds like you want a StreamResponse to be returned AND and a page refresh at the same time - unfortunately HTTP doesn't allow this. A technique would be return the page, then re-direct the user to a different page / event link which returns the CSV. It's also discussed in this thread: http://tapestry.1045711.n5.nabble.com/StreamResponse-on-Success-td2434690.html#a2434692 Steve. On 10 November 2011 19:08, goldenka wrote: > I have something linke: > > t:format="dd/MM/" t:type="DateField" validate="required" /> > > > and validation is server-side (onValidateForm() method) so I think i must > use JavaScript. Can you provide me some simple solution ? I think I must > remove some div's, but don't know how to do this... > > -- > View this message in context: > http://tapestry.1045711.n5.nabble.com/Clearing-form-errors-problem-tp4971307p4980738.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
I have something linke: and validation is server-side (onValidateForm() method) so I think i must use JavaScript. Can you provide me some simple solution ? I think I must remove some div's, but don't know how to do this... -- View this message in context: http://tapestry.1045711.n5.nabble.com/Clearing-form-errors-problem-tp4971307p4980738.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
On Thu, 10 Nov 2011 08:49:22 -0200, goldenka wrote: Thank you for your response. So can you tell me how to clear those errors because I have no idea how to do this? Are you using client-side validation? It will clear errors automatically. Any other solution will involve JavaScript, as HTTP supports only one response for each request. -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
Thank you for your response. So can you tell me how to clear those errors because I have no idea how to do this? -- View this message in context: http://tapestry.1045711.n5.nabble.com/Clearing-form-errors-problem-tp4971307p4980700.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
On Thu, 10 Nov 2011 08:31:28 -0200, goldenka wrote: Hi, I'm trying to clear errors which happened before - so eg. user inserted invalid date => pressed Download => error void onValidateForm() { if(dateTo == null) { form.recordError("Please insert valid date to!"); return; } } but after that user corrected the date and pressed Download => the file is downloading but the error "Please insert valid date to!" is still in the form. It's still there because you cleared the form errors server-side, not client-side. As you're returning a StreamResponse, no changes are done in the page DOM. In addition, as Steve said, onSuccess() will never be invoked with validation errors. -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
Hi, I'm trying to clear errors which happened before - so eg. user inserted invalid date => pressed Download => error void onValidateForm() { if(dateTo == null) { form.recordError("Please insert valid date to!"); return; } } but after that user corrected the date and pressed Download => the file is downloading but the error "Please insert valid date to!" is still in the form. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Clearing-form-errors-problem-tp4971307p4980644.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
Hi, I'm a bit confused... StreamResponse onSuccess() { form.clearErrors(); ... } OnSuccess() is only called when there are no errors in the form, so what are you trying to clear, and how do you know it's not working? Steve. On 10 November 2011 17:37, goldenka wrote: > StreamResponse onSuccess() { > form.clearErrors(); - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
Ok, I'm returning StreamResponse instead (in onSuccess() method). StreamResponse onSuccess() { form.clearErrors(); return new StreamResponse() { public String getContentType() { return "text/csv;charset=windows-1250"; } public InputStream getStream() throws IOException { return new ByteArrayInputStream(sb.toString().getBytes()); } public void prepareResponse(Response response) { response.setHeader("Content-Disposition", "attachment; filename="+filename); } }; } But again, form.clearErrors() don't work! -- View this message in context: http://tapestry.1045711.n5.nabble.com/Clearing-form-errors-problem-tp4971307p4980522.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Clearing form errors problem
On Mon, 07 Nov 2011 12:42:42 -0200, goldenka wrote: I'm using tapestry 5.0 and I have a problem with clearing form errors. > When "Download" button is pressed, and all form validation is OK I need to download a file. In order to do this in the onSuccess() method I get the HttpServletResponse object, set it's character encoding, content type etc. and after that I use its PrintWriter to generate CSV file (I'm using open CSV Library and it needs Writer object to generate csv). Instead, return a StreamResponse wrapping the generated file. You shouldn't use HttpServletResponse directly in Tapestry. -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Clearing form errors problem
I'm using tapestry 5.0 and I have a problem with clearing form errors. When "Download" button is pressed, and all form validation is OK I need to download a file. In order to do this in the onSuccess() method I get the HttpServletResponse object, set it's character encoding, content type etc. and after that I use its PrintWriter to generate CSV file (I'm using open CSV Library and it needs Writer object to generate csv). But when there where errors in the form, after pressing "Download" button they are not clearing (even after form.clearErrors() - because I used PrintWriter and HttpServletResponse and changed their content). Please can somebody help and tell how to clear these errors ? Thanks. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Clearing-form-errors-problem-tp4971307p4971307.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org