This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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

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 ]
GeeCON Prague 2014
subject: Display error messages in struts