• 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

2 submit buttons with different action

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have 2 buttons on one jsp, one is submit button and
the other is back. I want to use only one action form
to handle both the events, I am using
DynaValidatorForm.
So the problem i amfacing is, the fields get validated
even if i press the back button,
Is there a way to make sure that the validation occurs
only when i press submit button
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish,
You can define two action mappings in the struts-config.xml file which uses one action form.
So for the first tag you say validate=true and for another tag you say validate=false. If you specify validate=false then the validate method in action form does not execute.
For example
For submit button
-----------------
<action path="/submit" type="someclass" name="DynaValidateForm" validate="true" input="/xxx">
</action>
For back button
---------------
<action path="/back" type="someclass" name="DynaValidateForm" validate="false" input="/xxx">
</action>

I hope you find this info useful.
Loke.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think two actions using the same form is the question here. If I understand correctly you have two submit buttons on the same page and you want to post to a different action depending on which one was clicked?
There are three ways to do this:
1. use javascript to rewrite the form target prior to submission
2. hold a hidden field specifying which action is to be taken and just post to one Action class which does both things
3. Use DispatchAction class to forward the action on appropriately. (This is probably the best option)
Hope this helps
Jesse
 
lokesh reddy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jessi,
I think you dint got the problem completely. Pl have a look at the bold letters in the question and let met know your opinion.
I want to use only one action form to handle both the events. I am using DynaValidatorForm here he is talking about one action form handling two different actions and not two submit buttons handling one single action. And also the problem is with handling validations in the actionform i hope so.
Loke .
---------------
I am never afraid of tommorow, since i saw yesterday and i love today.
 
Jesse Beaumont
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry guys,
Ignore my ramblings above. I guess it's good practice to read the post one is replying to, huh
Jesse
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ashish kulkarni:
Hi,
I have 2 buttons on one jsp, one is submit button and
the other is back. I want to use only one action form
to handle both the events, I am using
DynaValidatorForm.
So the problem i amfacing is, the fields get validated
even if i press the back button,
Is there a way to make sure that the validation occurs
only when i press submit button


Since you are saying you are using one jsp, I will assume both buttons are on the same form and therefore submitting to the same action.
Set validation to false in your struts config file. In the action that is called, determine which button was pressed to submit the form. Depending on which button was pressed, manually call the form's validate method or use a validator class if appropriate.
[ December 31, 2002: Message edited by: Jason Menard ]
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rather than start a new topic, I decided to just dig this one back up since it is essentially the same problem I'm having.

I have two buttons that are supposed to submit to the same Action. One button is an actual "Submit" button that I want to require validation from my ActionForm. The other is a "Logout" button that should not be validated.

I have tried setting validation="false" in my struts-config for this action forward and then called the ActionForm's validate method directly from the Action class' submit method.

This partially works. It results in the Logout not requiring validation and logging out correctly.

Submit does validation and submits if validation passes and returns to the original JSP if validation fails.

The problem though is when returned to the original JSP I'm not able to display the ActionErrors because it is empty! How can I get this to stay populated using the method I have described?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IF
* You are allowed to use JavaScript
* Don't have to go to server to actually render the resulting page
THEN
* Add javascript code to go back when the user clicks on the back button.
You can do this by :
<input type=button value="back" onKlick="history.go(-1)">
reply
    Bookmark Topic Watch Topic
  • New Topic