• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to handle mutiple buttons

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have four different buttons on the JSP: Save, Submit, Return and Close.
These four buttons will save different data to the database.

Then how to write my action classes. Should I write seperate action class for every button
OR
One main action class and seperate methods for every button.

If so how to do this.

Please let me know.

Thanks in Advance.
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extend org.apache.struts.actions.DispatchAction, set parameter to method (or whatever) in struts-config.xml.

Html Submit buttons should be named method (or whatever) in the page.

When Struts processes it will call the appropriate method in the Action, methods should use same signature as execute, but, name them save, reset or whatever.
 
Chitti pokala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please give me some examples or websites where I can find more information on this.....
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And also u need this in JSP

<input type="hidden" name="method" value="save"/>
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'r action class :

public class LifeAActionbk extends DispatchAction {

public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

return mapping.findForward("list");
}


public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {


return mapping.findForward("edit");
}


}

struts-configfile

<action path="/edit" type="com.test.web.actions.LifeAAction"
name="dataForm" scope="session" parameter="method" validate="true" input="page.lifeA">
<forward name="edit" path="page.edit" />
</action>
 
Chitti pokala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to have different hidden fields for different buttons or only one hidden field for all the buttons.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do not go the route of hidden fields to handle this.

A popular method of handling multiple button isdescribed here with a link to LookupDispatchAction's javadoc, which has very good documentation.
[ August 12, 2005: Message edited by: Marc Peabody ]
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark may be right but I just followed Matt Raible "Equinox" application as a model. He used Hidden files in his jsp's.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sudhakar, do you set the value of the hidden field using javascript? I had been having problem with using javascript with struts...Could you please provide sample code?
[ August 12, 2005: Message edited by: michelle Wang ]
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have multiple buttons named the same thing whichever button you press will be submitted to the server.

Example:

<input type="submit" name="method" value="Add"/>
<input type="submit" name="method" value="Edit"/>
<input type="submit" name="method" value="Delete"/>

if the Add button is clicked method=add is submitted to the server

I think if you put <html:submit property="method" value="Add"/>
that should work.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kerry Wilson:
If you have multiple buttons named the same thing whichever button you press will be submitted to the server.

Example:

<input type="submit" name="method" value="Add"/>
<input type="submit" name="method" value="Edit"/>
<input type="submit" name="method" value="Delete"/>

if the Add button is clicked method=add is submitted to the server

I think if you put <html:submit property="method" value="Add"/>
that should work.



It doesn't matter if you use the Struts tag or not. It should work either way.
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, but you know some people just love to use tags when not necessary.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic