Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Struts
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2006, 12:57 AM
Registered User
 
Join Date: Jan 2006
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?

 
Old February 22nd, 2006, 07:12 AM
Authorized User
 
Join Date: Jan 2006
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
  }
}






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





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