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: <body> <logic:messagesPresent message="true" property="org.apache.struts.action.GLOBAL_MESSAGE"> <div class="errorHeader">The following error(s) occurred:</div> <ul> <html:messages property="org.apache.struts.action.GLOBAL_MESSAGE" id="message"> <li><bean:write name="message"/><br> </html:messages> </ul> </logic:messagesPresent> <form> <logic:messagesPresent message="true" property="username"> <div class="errorDetail"><html:errors property="username"/></div> </logic:messagesPresent> <input name="username"/> <logic:messagesPresent message="true" property="password"> <div class="errorDetail"><html:errors property="password"/></div> </logic:messagesPresent> <input name="password"/> </form> </body> -----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 <a> 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: <a href="#Username">Username</a> 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]