• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation Problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put validate="false" in struts-config.xml for the action that loads the page initially.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nick,
But I want to do validation from validation.xml.
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Nick....
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic