This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
vikas sharmaa
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic