This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Display error messages in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Display error messages in struts" Watch "Display error messages in struts" New topic
Author

Display error messages in struts

Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
Hi friends,
Iam new to struts, but presently working on it, how should display error messages by making the labels of the respective textboxs in a different color(for ex: say if First Name invalid then First Name in red) if possible plz do provide an example.

regards
shyam
Dharmanand Singh
Greenhorn

Joined: Oct 27, 2004
Posts: 13
Struts does not specifically provide any error handling for each and every form field like text box labels in your case. What it provides is a framework for error handling using the struts ActionError. You can add many such ActionError objects to an ActionErrors object in the Action class. Using saveErrors(request, ActionErrors) method provided in the action class, you can save the ActionErrors in the request. This can be accessed on the jsp by including the tag <html:errors/>. This will display all the errors that have been added via ActionErrors.
For your specific problem you might have to employ some logic to each of the form field labels and play on with their fonts. So, in the form bean you will probably need to keep the status of error for each of the form fields and then use that information to display the label in relevant font.
[ December 02, 2004: Message edited by: Dharmanand Singh ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Display error messages in struts
 
Similar Threads
Struts 2 - How do I remove validation messages from fields?
locale attribute in html:errors is not working
Help required on HelloWorld
Re, Handling Error using ActionMessages
Messages displayed only if I use saveErrors()