File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 submit buttons with different action

 
ashish kulkarni
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
lokesh reddy
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jesse Beaumont
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Jason Menard
Sheriff
Posts: 6450
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bloo Barton
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Navaneeth Rao
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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)">
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic