File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to focus on error field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to focus on error field" Watch "How to focus on error field" New topic
Author

How to focus on error field

Vipin Sahu
Greenhorn

Joined: Mar 08, 2007
Posts: 6
I am using validator framework and it is working fine. But is there any way to focus the cursor on the error field in struts. And how can we display only one error at a time.
Please help me!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Vipin Sahu:
is there any way to focus the cursor on the error field in struts.

Yes, with a combination of Javascript and the <logic:messagesPresent>. Just specify an onload event in the <body> tag that references a JavaScript function. Then in that function, code something like this:

If fields A, B, and C all have errors, focus will be on FieldC since it's the last in the list. You therefore might want to put the conditions in the reverse order of how they appear on the screen. That way the top field on the screen that has an error will get the focus.
Originally posted by Vipin Sahu:
how can we display only one error at a time.

You do this using the property attribute. If you want a separate field that only shows errors for fieldA, specify the following:


Merrill
Consultant, Sima Solutions
 
 
subject: How to focus on error field
 
Similar Threads
Is there a swing component or an awt component for an IPAddress Field
.focus()
Is onchange="submit()" will cause the loosing focus from current inputText field ?
How do I return focus to previous field
Validator