my dog learned polymorphism
The moose likes Struts and the fly likes struts & using js to change label text to red Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts & using js to change label text to red" Watch "struts & using js to change label text to red" New topic

struts & using js to change label text to red

Jeff Horan
Ranch Hand

Joined: Apr 03, 2003
Posts: 37
I'm looking for a nice way to change an input field's text label to red when there is an ActionMessage/ActionError generated by Validator. I'm handling the error message where global messages are displayed and I want to take the property names from the ActionMessage and change the label text to red based on the property name. I'm thinking fetching the labels' for attr (property) and get from the ActionMessage map. If it exists,then change the color.

Or there may be a slicker way of doing it. I'm open to suggestions.


Jeff Horan
Ranch Hand

Joined: Apr 03, 2003
Posts: 37
The problem with this approach or even just passing in a String[] of the properties that are in error is knowing how to get that info in to the request object. Does Validator put an object in the request ?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
this would work:

Note: use onlode was used above instead of onload to get around the JavaRanch filter.
[ October 25, 2006: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
say you have

how will you recognise "Your name" in order to change it's color? i dont think that's easy...

in my app, i'm not changing the field's description color but render a bold red error message right below the field.

there is a struts application property which leads and one that trails an error message. i'm using this fields to render

arround the error text. The style itself takes care of color, font style and of the required line break.

pretty satisfied with this solution :-)

[ October 26, 2006: Message edited by: Jan Groth ]
Nyanas Kandhan
Ranch Hand

Joined: Jan 27, 2009
Posts: 35
For an example on Highlighting Error Fields you can refer here.

Struts Highlighting Error Fields

Struts Developer

Shilpa Reddy V

Joined: Mar 17, 2008
Posts: 4
The link that Nyanas had mentioned does not seem to be working. Can someone provide me a solution to highlight the Label for example "Your Name" (refer previous messages by Jeff) to red on error. I am using bean:message to display the label on the page. Thanks
I agree. Here's the link:
subject: struts & using js to change label text to red
It's not a secret anymore!