Advertisement

11.20.2003 at 10:53PM PST, ID: 20804830
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

STRUTS: Multiple buttons in a form

Tags: struts, button, multiple
Hi experts!

My page has 4 buttons in one form. One is the submit button, another one is a cancel button, and the other two are buttons that does another action if chosen. (For example, delete and edit).

I use <html:img> or <html:image> tags for the buttons. I was wondering how I could get my action to determine which button was clicked and have the forward subsequently use the right method in my action.

Any help would be great. Thanks!

Thanks!

Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: rusco
Solution Provided By: kennethxu
Participating Experts: 6
Solution Grade: A
Views: 404
Translate:
Loading Advertisement...
11.21.2003 at 12:08AM PST, ID: 9795366

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 12:10AM PST, ID: 9795376

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 12:49AM PST, ID: 9795527

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 12:53AM PST, ID: 9795548

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 01:14AM PST, ID: 9795646

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 01:20AM PST, ID: 9795672

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 02:29AM PST, ID: 9795929

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 02:46AM PST, ID: 9795997

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 02:50AM PST, ID: 9796013

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.21.2003 at 11:06AM PST, ID: 9799203

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.22.2004 at 10:06AM PST, ID: 10651120

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.06.2004 at 11:06PM PDT, ID: 11246377

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.06.2004 at 11:10PM PDT, ID: 11246386

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.07.2004 at 06:30AM PDT, ID: 11249047

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
11.21.2003 at 12:08AM PST, ID: 9795366
You can do it like this:

<a href="/nextPage.do"><html:img src="/submit.gif" border="0" /></a>

or

<script>
  function gotoCancel(){
    document.yourForm.action=nextPage.do;
    document.yourForm.submit();
  }

</script>


<a href="javascript:gotoCancel()"><html:img src="/submit.gif" border="0" /></a>

Greetz,
Didier
 
11.21.2003 at 12:10AM PST, ID: 9795376
Forgot the quotes
   
 document.yourForm.action="nextPage.do";
 
 
11.21.2003 at 12:53AM PST, ID: 9795548
Hi Didier,

Just a quick question, when you use <a href="/nextPage.do"> this means that all of the buttons will have this link right? I mean, they will all go to one action but to the different methods of the action? Or does it mean having multiple actions? (mutiple .java/.class).

Thanks :-)
 
11.21.2003 at 01:14AM PST, ID: 9795646
Hi Kotan,

Will the link you sent me also work with <html:images> used as submit buttons? Just wanted to check. Thanks!
 
11.21.2003 at 01:20AM PST, ID: 9795672
I think can not. Then you can use its super class, DispatchAction

http://jakarta.apache.org/struts/api/org/apache/struts/actions/DispatchAction.html
 
11.21.2003 at 02:29AM PST, ID: 9795929
Hi Kotan,

Could you give me a code sample of how I could pass the the paramenter/method?

I tried using this:

        <html:link action="/RemoveConfigItem" paramId="method" paramName="remove">
        <html:image src="/ADM/images/delete_button.gif" border="0"/>
        </html:link>

But I get an error because it can't find the bean names remove. I was wondering how I'd be able to pass this :-)

Thanks!
 
11.21.2003 at 02:46AM PST, ID: 9795997
Hi rusco,

No, you can put the <a href="youraction"> ...........</a> around every html:img. Give them all a differnt value for href.


The same with the other example. You can make a function gotoCancel(), gotoOK(), gotoWhatever(), etc

Greetz,
Didier
 
11.21.2003 at 02:50AM PST, ID: 9796013

Rank: Sage

This is a good way of doing it (I think):

http://j2ee.lagnada.com/struts/html-buttons.htm
 
11.21.2003 at 11:06AM PST, ID: 9799203

Rank: Wizard

I always use a hidden field named as action, and for each button/image onclick, set the action to the various value. and in the formbean define action property to determine which button/image was clicked.
Accepted Solution
 
03.22.2004 at 10:06AM PST, ID: 10651120
DidierD,

I like what you are proposing, but I can't seem to get it to work.  I'm using LookupDispatchAction to determine which action method gets called when a button on the form is clicked (there are several buttons: add, save, exit).  I'm also using the Validator framework so that when I click the Add and Save buttons the form gets validated before the action class methods are executed (some fields on the form cannot be left blank for Add and Save).  But, I don't want validation to occur when I click the Exit button (because user should be able to exit from a blank form).   So, I want to change the form action to /exit.do when the Exit button is clicked (in struts-config.xml the action mapping for /exit.do has validate='false' to prevent the form from being validated before going to the action class's exit() method).  Here are the pieces:

Action mappings from struts-config.xml:
<action path="/theformaction" name="myForm" type="CommonActions" validate="true" input="/thejspfile.jsp" parameter="methodToCall" scope="request" >
      <forward name="success" path="/success.jsp" />
      <forward name="failure" path="/failure.jsp" />
</action>
<action path="/exit" name="myForm" type="CommonActions" validate="false" parameter="methodToCall" scope="request" >
      <forward name="mainmenu" path="/mainMenu.jsp" />
</action>

(myForm is of type org.apache.struts.validator.DynaValidatorForm, CommonActions is a subclass of org.apache.struts.actions.LookupDispatchAction).

Button code from thejspfile.jsp:
<html:submit property="methodToCall">
      <bean:message key="button.add"/>
</html:submit>
<html:submit property="methodToCall">
      <bean:message key="button.save"/>
</html:reset>
<input type="button" name="methodToCall" value="Exit" onclick="javascript:exit()">
<script>
      function exit(){
            document.forms[0].action="/exit.do";
            document.forms[0].submit();
      }
</script>

Struts uses the methodToCall parameter to figure out which method in my LookupDispatchAction subclass to execute.  It works fine for the add and save buttons (validation occurs, then the add() or save() methods run), but when I click the exit button, I get a runtime exception:

javax.servlet.ServletException: Request[/exit] does not contain handler parameter named methodToCall.

This is what the form buttons look like with view source:

<input type="submit" name="methodToCall" value="Add">
<input type="submit" name="methodToCall" value="Add">
<input type="button" name="methodToCall" value="Exit" onclick="javascript:exit()">

Apparently, the methodToCall parameter isn't being added to the ActionMapping object, but I don't know why.  Very sorry this is so long, but I wanted to provide a complete description.  

Note that I know this works:

<input type="button" value='Exit' onclick='window.location="mainMenu.jsp";'>

 but I don't want to do that, because then the path to the jsp file is displayed to the user in the URL.

Thanks for any help.
 
06.06.2004 at 11:06PM PDT, ID: 11246377
To make buttons work:

JSP:
 <html:submit property="submit">
                          <bean:message key="button.add"/>
                </html:submit>

note:  there has to be space between the " /> .

1. property can be any name you want but you will have to remember this because this is what you will need for parameter name in the struts-config file.

2. The key to the button is called button.add.  You can make any name you want.  You can call it e.g. butt.pizza.  You will also have to remember this because you will need to add this name in the file ApplicationResources.properties.  In the applicationResources.properties, you do your translation.  button.pizza=Nice Job.   note:  no space in the equal.   This is why this makes struts more extensible.  

3. You will need to change the struts-config file:

 <action path="/doSomething"
            type="com.fitness.pt.actions.doSomethingAction"
            name="measurementForm" scope="request" parameter="submit" validate="false">
      <forward name="success" path="/doSomething.do"/>
    </action>

please note parameter="submit"  this is the property in the .jsp
validate can be false or true since I do not have a validation file, I set it to false.

4.  You will need only one java class to control your routing.  I think this makes it cleaner.  You will need to import LookupDispatchAction.  Please do not inherit PTBaseAction since it has an execute() method.  If you do that, this overrides the execute method of the LookupDispatchAction.  I do not know how to make a PTLookupDispatchAction to make the codes reusable because you have to implement getKeyMethodMap();

The method getKeyMethodMap() is your database.  This tells the class what your button.pizza has to do.  map.put("button.pizza", "buyPizza");    Then you need to implement a method called buyPizza().



  protected Map getKeyMethodMap() {
    Map map = new HashMap();
    map.put("button.update", "update");
    map.put("button.delete", "delete");
    map.put("button.add", "add");
    map.put("button.save", "save");
    return map;
  }

    public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    System.out.println("called the update");
    return mapping.findForward("success");
  }

  public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    System.out.println("called the delete");

    return mapping.findForward("success");
  }
   public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    System.out.println("called the update");
   
    return mapping.findForward("success");
  }

  public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    System.out.println("called the delete");
    return mapping.findForward("success");
  }
}

 
06.06.2004 at 11:10PM PDT, ID: 11246386
I made a mistake in the following>  I used these codes in my application and these are the notes to my colleagues.  I forgot to take out all the application specific codes.  These are:

1. PTBaseAction is specific to our application.  The codes are tested and it works
 
06.07.2004 at 06:30AM PDT, ID: 11249047
zenMistress2004, thanks for the reply.  I actually did get this to work using the following for my exit button code:

<input type="button" value="Exit" onclick='document.forms[0].action="exit.do";document.forms[0].submit();'>

I changed the mapping in struts-config.xml to the following:

<action path="/exit" type="TheCommonActions" parameter="exitToMenu" >
      <forward name="mainmenu" path="/hospcapMenu.jsp" />
</action>

TheCommonActions is a new class extending MappingDispatchAction.  "exitToMenu" is the name of a method in the class.  The method simply has the following return statement:

return actionMapping.findForward("mainmenu");

BTW, regarding your comment that there has to be a space between the " and the /> terminating the <html:bean tag, I don't have a space there and it works fine.
 
 
20080236-EE-VQP-29