The moose likes Struts and the fly likes Highlight the Field in Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Highlight the Field in Validation" Watch "Highlight the Field in Validation" New topic
Author

Highlight the Field in Validation

Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 106
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.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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>


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Highlight the Field in Validation
 
Similar Threads
struts validation
jakarta struts and validation
Question about ActionError of Struts
Very Urgent : Fututre Date validation using struts validation
Validation Solutions/Frameworks