Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one form, three actions?

 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is really very basic question but I am not clear. This is my signIn.jsp file:



How can I send three different events from the same form?

In other words, There are three buttons at my page and I want different action on each click of each button. How could I do this??? or how can I know at server side that which button has been clicked by user???

I am sure there must be many ways of doing this, please tell me the simpler one and best one.

Thanks a lot.


[ November 26, 2005: Message edited by: Bear Bibeault ]
 
Oswald King
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
specify same name attribute for all the 3 submit buttons in your code


and then in your MainController :
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64190
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, use Javascript to change the action of the form upon clicking one of the submit buttons.
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Or, use Javascript to change the action of the form upon clicking one of the submit buttons.


But all the requests are going first to MainController servlet so action is same in all the cases.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
But all the requests are going first to MainController servlet so action is same in all the cases.


Sounds like you are using Front Controller Pattern. You can make the decision in your MainController on the basis of button value, as Oswald King already suggest said.

Think of implementing Command Pattern.
[ November 28, 2005: Message edited by: Adeel Ansari ]
 
Paul Clapham
Sheriff
Pie
Posts: 20191
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or put the three buttons in three different forms.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64190
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by babu amara:

so we have to write the code like below.

<INPUT type="submit" value="Sign In" action="A.html">

in the same way for below two also.
<INPUT type="submit" value="Sign Up" action="b.html">
<INPUT type="submit" value="Forgot Password" action="c.html">


Nonsense. There is no action attribute on the input tag.
[ November 28, 2005: Message edited by: Bear Bibeault ]
 
C Broussard
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is where the beauty of struts comes into play (or any standardized framework for that matter). Struts has a DispatchAction w/ an actionMethod defined in the struts action definition for this use case. why try to reinvent the wheel instead of using the wheel for leverage.

www.binaryfrost.com
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C Broussard:
this is where the beauty of struts comes into play (or any standardized framework for that matter). Struts has a DispatchAction w/ an actionMethod defined in the struts action definition for this use case. why try to reinvent the wheel instead of using the wheel for leverage.

www.binaryfrost.com


[highjack]
Because sometimes the wheel becomes a monster truck tire when a bicycle tire would have sufficed. Sometimes reinventing the wheel is a good thing.
[/highjack]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64190
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adopting a bloated behemoth like Struts in order to accomplish a simple switch would be a tad bit of overkill, in my opinion.
 
C Broussard
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, don't shoot the messenger. j/k. I agree that this single example here doesn't provide enough of a business case to switch a bunch or adding a bunch of code around. here's some stuff to keep in mind. if he was using a standardized framework he most likely wouldn't be posting this question, he'd be posting a much more difficult question Ha Ha!. But seriously, this problem has already been addressed by someone else and solved. secondly, this is the signIn.jsp. sounds like he's doing more than a 20 action application, so it starts to warrant a standardized approach for long term maintainability, not some home-grown application... of course I could be completely off base.. I did join the party late.

www.binaryfrost.com

ps.. one other thing.. struts isn't bloated.. JSF is bloated
[ November 28, 2005: Message edited by: C Broussard ]
 
Babar Qadri
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C Broussard:
ps.. one other thing.. struts isn't bloated.. JSF is bloated


Hey, dont say a word to JSF.

I always did with my own fabricated framework. After JSF, I joined the JSF team and still working with JSF. Its good a bit immature but real good, simple, sensible. Its a component based framework and easily digestable. JSF is something really works and has a great future.

By the way, the discussion is going off topic.

I guess you dont know what she is doing. From her previous posts I got to know that she made her own mini web framework based on MVC architecture and going great with that, I hope. So, struts, or something else is meaningless for her right now.

I would also suggest the same, what Adeel and Oswald already suggested.
[ November 28, 2005: Message edited by: Babar Qadri ]
 
sruthi adhuri
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try This....

<HTML>
<HEAD>
<SCRIPT language="JavaScript">
function processForm(action)
{
if(action == "Sign In")
{
document.frm.action = "MainController";
}
else if(action == "Sign Up")
{
document.frm.action = "MainController1";
}
else if(action == "Forgot Password")
{
document.frm.action = "MainController2";
}
else
{
return;
}
document.frm.submit();

}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="frm" method="post">
username<INPUT type="text" name="username"/><br>
password <INPUT type="text" name="password"/><br>
<br>
<INPUT type="button" value="Sign In" onClic="processForm('Sign In')">
<INPUT type="button" value="Sign Up" onClic="processForm('Sign Up')">
<INPUT type="button" value="Forgot Password" onClic="processForm('Forgot Password')">
</FORM>
</BODY>
</HTML>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic