• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Struts 1: Selective Validation of Form

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have page with multiple buttons.

One To perform search based on criteria and bring up a list of records matching the criteria. and the few buttons to open a new page based on the selected record from the list.

Is it advisable to use one Form or two Action forms for this page?

If a single form, should I go for Action/LookupDispatchAction?

I would prefer a single form and Action.
If I set validate="true" for the action mapping, validation runs no matter what button I click.

I need validtion (using validation.xml) to run only, when I do the search using the criteria. But if the user is clicking any of the other buttons to go to a new page, validation should not run. Is there any way I can do this with just one form?

Thanks in advance.

Deena
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use html:submit tag for search button and html:cancel tag for others. Struts will bypass validation when those buttons are pressed.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have page with multiple buttons.



One To perform search based on criteria and bring up a list of records matching the criteria.



and the few buttons to open a new page based on the selected record from the list.



Is it advisable to use one Form or two Action forms for this page?



You should have two ActionForm for this page. (1) One to handle the criteria-based search. (2) And the other to handle the selected record display.

Have two action elements in the struts-config.xml file which point to the same Action class. This will enable you to have a single Action class handle processing with the two ActionForms.
 
Deena Jeyachandran
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can use html:submit tag for search button and html:cancel tag for others. Struts will bypass validation when those buttons are pressed.



I understand this will work, if I use the regular Struts Action. If I use with LookupDispatchAction, I get the error "does not contain handler parameter named parameter". I think it is because LookupDispatch expects property in submit to match the parameter field value defined in struts config. But I have left the property field blank as adviced in html:cancel tag description
"Property - Name of the request parameter that will be included with this submission, set to the specified value. WARNING - If you set this attribute to a value other than the default, this will NOT be recognized as the cancel key by the Struts controller servlet or the Action.isCancelled() method. You will need to do your own cancel detection."
The struts API for Lookup dispatch action quotes
"If the submit was cancelled (a html:cancel button was pressed), the custom handler cancelled will be used instead. "

Could you suggest, what I can do?
[ December 23, 2008: Message edited by: Deena dayal Jeyachandran ]
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code the application to use the regular Struts Action class for this page and these forms.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or write a "cancelled" handler?
 
Cendy Van
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you decide to use a LookupDispatchAction, don't use html:cancel tag.

Here is another solution :

you can specify validate="false" in the action mapping in your struts-config.xml file and call validation only in search method like this :

[ December 24, 2008: Message edited by: Cendy NVY ]
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic