Meaningless Drivel is fun!
The moose likes Struts and the fly likes Validate method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validate method" Watch "Validate method" New topic

Validate method

Anjana Krishniah

Joined: Jun 28, 2002
Posts: 3
I have a 'MyForm' link on the menu of my page which brings up a form when clicked. I have implemented validate method in the above form class......
When a form is submitted, validate method checks for the null or empty fields and prompts the user the enter the fields if they are not entered, giving them the error messages.
But the problem is, when the user cliks on the 'MyForm' twice, ie without filling the form, if the user clicks the link, then it is calling the validate method and displaying all the error messages.... How do I avoid to display the validation errors when the user clicks on the link again.
I cannot remove the hyperlink on 'MyForm', when the user is already on that page, because I am creating the menu buttons in another taglib, at the beginning of the I have no way of knowing in which page the user is...
How do I know in my form java class that the user has not submitted the form, and treat it like a fresh request, when the user clicks on the link again??

Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
How about storing some kind of state in the HttpSession?
Your taglib could then get the information from the session or you could pass the information to the tag as an attribute.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Erik Hatcher
Ranch Hand

Joined: Jun 11, 2002
Posts: 111
I use Struts extensively, and I code it such that there are two action mappings to the same Action subclass and form, with the difference being that one has validate="true", and the other validate="false". Maybe this would apply to your situation?

Co-author of Lucene in Action
I agree. Here's the link:
subject: Validate method
It's not a secret anymore!