permaculture playing cards*
The moose likes Struts and the fly likes Struts 2: how to distinguish multiple submit button call in the action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2: how to distinguish multiple submit button call in the action class" Watch "Struts 2: how to distinguish multiple submit button call in the action class" New topic
Author

Struts 2: how to distinguish multiple submit button call in the action class

vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
i have implemented a simple login application in Struts 2. In the login page, i added 2 buttons. first button is for the new user registration process and second button to login process for existing users. Now, on click of either button calls the execute method of the same action class. how could i distinguish them in the execute call? for your reference, login.jsp is attached below:



please tell me the best way of implementing the above logic in struts 2.
Gopi Chand
Greenhorn

Joined: Feb 04, 2007
Posts: 24
I guess it is not possible to have two submit but for a single form.. why can't you make "sign-up" as a hyperlink, since sign-up just have to open the register page and you really don't have any information to send to the server..
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
thanks gopi chand, it seems to be a better approach. but, from the learning struts approach, i want to implement 2 buttons on the same form. and then on click of those buttons, separate process executed. i am able to put 2 submit buttons on the same form with different name as mentioned in the login.jsp file of my first post. but am not able to distinguish them in the execute method call.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8877
    
    8

The value of the submit button, like all the other HTML input tags, gets submitted with the form in a variable which has the same name as the "name" parameter (in your code, "signin" and "newuser"). You can add those two variables to your Action and check which one gets set.
Another solution would be to use JavaScript to change the target of the form depending on which button is pressed. See here for an example.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2: how to distinguish multiple submit button call in the action class