aspose file tools*
The moose likes Struts and the fly likes Validation Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation Problem" Watch "Validation Problem" New topic
Author

Validation Problem

Shibin Paul
Greenhorn

Joined: Dec 11, 2006
Posts: 18
I have got a form ,which I need to validate using validation.xml.To reach this form I use a link forward from the main page.This form has some values which get filled from the database so the action needs to be executed atleast once.But when if the action gets executed (using link action) for getting data from the database the validation happens and results in display of all errors when the page is first displayed.

Can anyone tell me the solution for this problem.

Thanks in advance.
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
Put validate="false" in struts-config.xml for the action that loads the page initially.
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
yes, and then you have to manually call the validation method in your action when you submit the form. myform.validate(mapping, request);
Shibin Paul
Greenhorn

Joined: Dec 11, 2006
Posts: 18
Nick,
But I want to do validation from validation.xml.
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
the only way around that is have the initial link to view the page have a different mapping. (double map your action)

...
//this one is to view the page
path="myaction-init"
type="org.my.class"
validate="false"
...

...
//this one is to submit the form
path="myaction"
type="org.my.class"
validate="true"
...

then you link to get to the page would be myaction-init.do and you form would submit to myaction.do
Shibin Paul
Greenhorn

Joined: Dec 11, 2006
Posts: 18
Thank you Nick....
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Good advice from Nick. If you think about it the term "action" implies that something is happening...a verb. My general naming convention is to have a verb as part of my action name. I don't have an "Employee" action. Instead I have a "DisplayEmployee" action and a "SaveEmployee" action.

- Brent
kiran reddy
Greenhorn

Joined: Dec 04, 2006
Posts: 3
Hello Nick,

In Struts-Config.xml file i made the validation="false".
then then validation is not happening.
I am using the Dispatch action. If validation="True" means while page loading itself validation happens.

Can you explain the solution clearly. I di't understand.

-- Kiran
Nick Williamson
Ranch Hand

Joined: Jan 06, 2007
Posts: 73
when you put validation="true" every time you hit that action it will validate the backing form configured. So if you have a dispatch action with methods like setup, add, edit, delete, or what have you, you're still hitting that action. When you hit the action struts looks at the config to which action you're going to. It'll say oh this action is MyDispatchAction, then it sees that validation is set to true and tries to validate it, no matter what method it's going to dispatch to.

When using dispatch action I normally just call the form validation from the methods that need to be validated.

the struts validation flag is set to the action, not each individual method.

You could get tricky and override the dispatch method look for the name of the method and validate it if it falls within the methods you want to validate, if you do that, look at the source code to dispatch action and see what it's doing and you'll get the idea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validation Problem