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 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" Watch "Validate method" New topic
Author

Validate method

Anjana Krishniah
Greenhorn

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 JSP...so 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??

Thanks
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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
Author
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: http://aspose.com/file-tools
 
subject: Validate method
 
Similar Threads
Getting form values via html:link
How to add error message before sendRedirect
Form Validation and Delete using struts
How to disable a href link after it is clicked once
Back button behaviour