This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes validate() Method in action form 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 "validate() Method in action form" Watch "validate() Method in action form" New topic

validate() Method in action form

shaggy lype

Joined: Apr 02, 2004
Posts: 21
I am implementing struts validator in my application and using struts 1.1. I am trying to validate certain conditions in the validate() method of the struts action form. How can we display errors generated for a particular text field beside that field in the JSP?
I would really appreciate your help in this regard.

Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Inside the function, you can do this:


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Another solution:

You can using <html:errors/> tag in jsp page to display errors.
shaggy lype

Joined: Apr 02, 2004
Posts: 21
Thank you for your reply, but i guess my question has not been interpreted correctly. My problem is that suppose there are 3 text fields in a page say textfield1, textfield2 and textfield3. Then in the validate method of the action form, i do some checks and if there are any errors generated say by textfield1, how would i display the error for that field beside textfield1 in the jsp. In a similar way suppose textfield2 fails the validations, how could i display the error related to textfield2 beside it. The same for textfield3 and so on.
I hope i was able to present my question much clearly this time. I would really appreciate any suggestions to tackle this.
Praveen Teegala

Joined: Apr 03, 2004
Posts: 11
Where ever you want to display the error message in JSP,
add the code like this,
<html:messages id="errorx" property="Error1">
<bean:write name="errorx"/>
where "Error1" is the error that you have added in the
validation method.
Hope this helps.

shaggy lype

Joined: Apr 02, 2004
Posts: 21
Thank you Praveen. It sure did help me.
I agree. Here's the link:
subject: validate() Method in action form
Similar Threads
difference between and validate() and validation.xml
Action class execute method not getting called
Struts Design Problem
validate() method & validation.xml
Running a validation on specific action.