Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > Struts
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Struts section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 22nd, 2006, 12:57 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to know whick button was clicked.

Good day to all,

    I am new to struts. I have a form that has three buttons. I am using dispatch action to go to my blogic. How do I determine which button was clicked?

Reply With Quote
  #2 (permalink)  
Old February 22nd, 2006, 07:12 AM
Authorized User
 
Join Date: Jan 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to longjava
Default

One of the way you can do is having a javascript setting a hidden field before the form sending data to the server.

Here is an example how to do it:

From the client:
---------------
<script type='text/javascript'>
function setHiddenField( buttonName )
{
   document.myForm.buttonType.value = buttonName;
}
</script>
<form name='myForm'>
  <input type='hidden' name='buttonType' value="">
  <input type='button' value='Button1' onclick="setHiddenField('button1')">
  <input type='button' value='Button2' onclick="setHiddenField('button2')">
  <input type='button' value='Button3' onclick="setHiddenField('button3')">
</form>

From the server:
---------------
public class MyAction extends DispatchAction
{
  public ActionForward myMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServeltResponse response)
  {
    String whatButton = form.getButtonType();
    .... do business logic here
  }
}

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form does not open when commandbar button clicked Arsi BOOK: Professional Outlook 2007 Programming ISBN: 978-0-470-04994-5 21 March 5th, 2009 04:03 AM
Determining Which Button Was Clicked BrianWren ASP.NET 1.0 and 1.1 Basics 3 May 5th, 2005 03:24 PM
How to tell which button clicked emily PHP How-To 2 November 30th, 2004 01:35 PM
links to a page when a button is clicked hosefo81 HTML Code Clinic 4 December 7th, 2003 06:47 AM



All times are GMT -4. The time now is 10:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.