Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

validate() Method in action form

 
shaggy lype
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

shaggy
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside the function, you can do this:

Nick
 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another solution:

You can using <html:errors/> tag in jsp page to display errors.
 
shaggy lype
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
thanks
shaggy
 
Praveen Teegala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"/>
</html:messages>
where "Error1" is the error that you have added in the
validation method.
Hope this helps.
Praveen.
 
shaggy lype
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Praveen. It sure did help me.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!