RE: Different error messages for client and server side validation
What I spoke of doesn't really address your immediate issue, which was how could you use different error messages for client-sided and server-sided validation. It's more of a workaround as it eliminates the need to have your error messages contain links to the fields. Have you ever filled out a form where invalid field values result in a big bold error message being rendered directly above the field that contained the invalid value? That's what this would do. Invalid values would result in a javascript alert box containing plain text ("Username is required") for clients with javascript enabled. Script-disabled browsers would have an error box at the top of the page containing something like "Please correct the errors below", and the username text box would have big red text above it reading "Username is required". Unless your form is many pages long, linking to the errors would perhaps be considered a novelty. If your form really is that long, you may want to consider breaking it up into multiple pages. Just a thought. In your action class: public ActionForward execute(req, res, form, mapping) { ActionMessages failures = null; if(form.getUsername() == null) { failures.add("username", new ActionMessage("error.username")); failures.add(ActionMessages.GLOBAL_MESSAGE, new ActionError("validation.failure"); } saveMessages(req, failures); ... } Your JSP page: The following error(s) occurred: -Original Message- From: Dimitris Mouchritsas [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 30, 2008 12:13 PM To: Struts Users Mailing List Subject: Re: Different error messages for client and server side validation Kawczynski, David wrote: > Your Action classes can add ActionMessages for a specific property, not > just GLOBAL_MESSAGES. > Then, display GLOBAL_MESSAGES at the top of the page, and field-specific > ones relative to the field. > (this will work in 1.3.8) > > See > http://struts.apache.org/1.2.7/api/org/apache/struts/action/ActionMessag > es.html > > Specifically: > add(java.lang.String, org.apache.struts.action.ActionMessage) > get(java.lang.String) > > -Original Message- > From: Dimitris Mouchritsas [mailto:[EMAIL PROTECTED] > Sent: Tuesday, September 30, 2008 11:23 AM > To: Struts Users Mailing List > Subject: Re: Different error messages for client and server side > validation > > Dimitris Mouchritsas wrote: > >> Hi all, >> we are using elements in our error messages to allow the user to >> go to the form field when the error message shows up. >> Obviously this messes up the client side javascript popup message >> which shows like: Username is missing. >> Is there a way to use a different error message or should we abandon >> the idea of client side validation? >> >> Regards >> Dimitris Mouchritsas >> >> > BTW Struts v1.3.8 > > > Can you please elaborate with a small example? I don't get it. Thanks - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different error messages for client and server side validation
Kawczynski, David wrote: Your Action classes can add ActionMessages for a specific property, not just GLOBAL_MESSAGES. Then, display GLOBAL_MESSAGES at the top of the page, and field-specific ones relative to the field. (this will work in 1.3.8) See http://struts.apache.org/1.2.7/api/org/apache/struts/action/ActionMessag es.html Specifically: add(java.lang.String, org.apache.struts.action.ActionMessage) get(java.lang.String) -Original Message- From: Dimitris Mouchritsas [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 30, 2008 11:23 AM To: Struts Users Mailing List Subject: Re: Different error messages for client and server side validation Dimitris Mouchritsas wrote: Hi all, we are using elements in our error messages to allow the user to go to the form field when the error message shows up. Obviously this messes up the client side javascript popup message which shows like: Username is missing. Is there a way to use a different error message or should we abandon the idea of client side validation? Regards Dimitris Mouchritsas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] BTW Struts v1.3.8 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Can you please elaborate with a small example? I don't get it. Thanks - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different error messages for client and server side validation
Geia sou wre Dimitri. Dimitris Mouchritsas wrote: we are using elements in our error messages to allow the user to go to the form field when the error message shows up. Obviously this messes up the client side javascript popup message which shows like: Username is missing. Is there a way to use a different error message or should we abandon the idea of client side validation? You could modify the JS file in the struts JARs (cant remember where it is) and modify the code to strip the markup from the alert() *only*. A function to strip markup is stripTags = function (s) { return s?s.replace(/<[^>]+>/g,""):s; }; so you could modify e.g. alert(errors); to alert(stripTags(errors)); Xeraitismata ston Pitarokili, to Valassopoulo kai to Nikita ;-) Cheers, Manos - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Different error messages for client and server side validation
Your Action classes can add ActionMessages for a specific property, not just GLOBAL_MESSAGES. Then, display GLOBAL_MESSAGES at the top of the page, and field-specific ones relative to the field. (this will work in 1.3.8) See http://struts.apache.org/1.2.7/api/org/apache/struts/action/ActionMessag es.html Specifically: add(java.lang.String, org.apache.struts.action.ActionMessage) get(java.lang.String) -Original Message- From: Dimitris Mouchritsas [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 30, 2008 11:23 AM To: Struts Users Mailing List Subject: Re: Different error messages for client and server side validation Dimitris Mouchritsas wrote: > Hi all, > we are using elements in our error messages to allow the user to > go to the form field when the error message shows up. > Obviously this messes up the client side javascript popup message > which shows like: Username is missing. > Is there a way to use a different error message or should we abandon > the idea of client side validation? > > Regards > Dimitris Mouchritsas > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > BTW Struts v1.3.8 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different error messages for client and server side validation
Dimitris Mouchritsas wrote: Hi all, we are using elements in our error messages to allow the user to go to the form field when the error message shows up. Obviously this messes up the client side javascript popup message which shows like: Username is missing. Is there a way to use a different error message or should we abandon the idea of client side validation? Regards Dimitris Mouchritsas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] BTW Struts v1.3.8 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]