• 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

Handling buttons with same names in two forms using a single Action class.

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have 2 forms with the same button value i.e continue.In Scenario A, the click of the button should call method edit(),and in Scenario B, the click of the button should call method verify().
I have written an Action class that subclasses LookupDispatchAction.

My problem is that in my getKeyMethodMap() method of my Action, I am
trying unsuccessfully to map the method names to the button value.

This is how my getKeyMethodMap method looks like:

-----------------------------------------------------------
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("setup", "setup");
map.put("scenarioA.continue", "edit");
map.put("scenarioB.continue", "verify");
return map;
}

My property file has these entries.
Setup=setup
Verify=verify
scenarioA.continue= continue
scenarioB.continue= continue
---------------------------------------------------------------------

Can anyone suggest how I can achieve this in Struts?


MY RESOLUTION:
I resolved the issue by mapping both of these to a method called getCorrectMethod where I checked for the value of a hidden field to determine which method to invoke.
-------------------------------------------------------
Code:
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("setup", "setup");
map.put("scenarioA.continue", "getCorrectMethod");
map.put("scenarioB.continue", "getCorrectMethod");
return map;
}


public ActionForward getCorrectMethod (
ActionContext context,
ActionMapping mapping,
BaseActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws ServiceFrameworkException, ActionFrameworkException {

String nextScreen = request.getParameter("screenName");
if (nextScreen.equals("ScenarioA")) {
return edit(context, mapping, form, request, response);
} else if (nextScreen.equals("ScenarioB")) {
return verify(context, mapping, form, request, response);
}
}
--------------------------------------------------------


But, I need to achieve this without using hidden fileds. DOes anyone have
a better resolution to t he p[roblem I am facing? It would be of immense help.

Thanks,
Scorp N.
 
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
Scorp,

Check out my solution here:
http://marcpeabody.com/commanddispatch.html

These classes allow you to specify the Action method in the property attribute of the struts button like so:
your page 1 -
<html:submit property="command(edit)" value="Continue">
your page 2 -
<html:submit property="command(verify)" value="Continue">

OR if you want to use regular html instead of html:submit...
your page 1 -
<input type="submit" name="command(edit)" value="Continue">
your page 2 -
<input type="submit" name="command(verify)" value="Continue">

It's easy to use. If you have any questions, feel free to send a Private Message my way.

Cheers!
 
Nivan scorp
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Mark,
Thanks for your valuable suggestion. Its been of great help.

Regards,
Nivan.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic