Stella:
Any time you incorporate Javascript into your app, you have to wonder if things
will work now/ever/always in this/that/other browser. So avoiding everything
except the most basic javascript may be a good idea.
What you want to do can be done more cleanly (just in my opinion though) in the
following way:
Write an interface say "MyRequestHandler" with just one method: public String
handleRequest(MyForm);
write classes like "UpdateShopWorkOrderRequestHandler" and
"CreateShopWorkOrderRequestHandler" which implement MyRequestHandler: all the
work gets done here: You have access to the form bean (via the argument) and in
the end you will return a string (which will be used to create your
ActionForward).
Write a suingleton class MyRequestHandlerFactory: all it does is have a hashmap
mapping "actionCommand" strings to appropraite instances of the RequestHandler:
For example: you may have an entry in the hashmap as:
myHandlerMap.put("updateShopWorkOrder", new
UpdateShopWorkOrderRequestHandler());
myHandlerMap.put("createShopWorkOrder", new
CreateShopWorkOrderRequestHandler());
Write a constructor which will construct your hashmap, and write a getInstance
method in the usual way:
public static MyrequestHandlerFactory getInstance()
as well as a
public MyRequestHandler getRequestHandler (String actionCommand)
which just consults the hashamp and returns the appropriate handler.
Finally, write a "superAction" so:
public class MySuperAction extends Action {
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
String actionCommand = request.getParameter("actionCommand");
MyRequestHandler requestHandler =
MyRequestHandlerFactory.getInstance().getRequestHandler(actionCommand);
String forwardString = requestHandler.handleRequest((MyForm) form);
if (mapping.findForward(forwardString) == null) log.debug("path is
null!"); //this si probably an error condition!
else log.debug("Path is : " +
mapping.findForward(forwardString).getPath()); //bingo!
return mapping.findForward(forwardString);
}
I think this method works quite well and has the advantage of simplicity too..
Hope this helps.. Good luck and let me know if you'd like any more
elaboration..:)
Geeta
"Au-Yeung, Stella H" wrote:
> Paul and Hubert:
> If I do the following, just choose one of the paths to be the <html:form
> action="...">, you mean the form action can still be "dynamically
> overwritten" by what is actually picked in the submitForm() action? I
> thought I tried that and didn't work.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]