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 Struts 1: Selective Validation of Form 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 "Struts 1: Selective Validation of Form" Watch "Struts 1: Selective Validation of Form" New topic
Author

Struts 1: Selective Validation of Form

Deena Jeyachandran
Greenhorn

Joined: May 24, 2008
Posts: 18
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


Preparing SCBCD.....
Cendy Van
Greenhorn

Joined: Nov 06, 2007
Posts: 6
You can use html:submit tag for search button and html:cancel tag for others. Struts will bypass validation when those buttons are pressed.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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

Joined: May 24, 2008
Posts: 18
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

Joined: Apr 16, 2008
Posts: 2187
Code the application to use the regular Struts Action class for this page and these forms.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Or write a "cancelled" handler?
Cendy Van
Greenhorn

Joined: Nov 06, 2007
Posts: 6
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 1: Selective Validation of Form
 
Similar Threads
validation on submit and not on other page actions?
link css style sheet
DispatchAction question
I want two buttons on a page, one for "search refine", one for "submit", how to do ?
Some questions about b&s