File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Display error messages in struts" Watch "Display error messages in struts" New topic

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.

Dharmanand Singh

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 ]
I agree. Here's the link:
subject: Display error messages in struts
It's not a secret anymore!