• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Highlight the Field in Validation

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

My jsp page gets validated fine and it displays errors. I am using server-side validation of struts.

The question I have is suppose there is a text field for example say: "LastName" If I do not fill it shows "Last Name is Required" But can any one help me that when this error is displayed, I also want to highlight the field with an "yellow" or any color. How can we do this on struts?

Thank you very much for your time in advance.

Luke.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to do this, you will have to use javaScript, but Struts can certainly do some of the work. Here's one way to do it:

in your Action class:

errors.add("lastName", new ActionMessage("error.lastname");

in your jsp:
<head>
<script>
function init() {
<logic:messagesPresent property="lastName">
document.getElementById("lastNameLabel").style.color = "yellow";
</logic:messagesPresent>
}
</script>
</head>
<body>
<html:form action="myaction" on load="init()">
<div id="lastNameLabel">Last Name:</div>
<html:text property="lastName"/>
...
</html:form>
</body>
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic