Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts & using js to change label text to red

 
Jeff Horan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks
 
Jeff Horan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :-)

jan
[ October 26, 2006: Message edited by: Jan Groth ]
 
Nyanas Kandhan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For an example on Highlighting Error Fields you can refer here.

Struts Highlighting Error Fields

regards
Struts Developer

 
Shilpa Reddy V
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic