Announcement Announcement Module
Collapse
No announcement yet.
MultiActionController setBindOnNewForm(true); Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MultiActionController setBindOnNewForm(true);

    Hi All,

    How can i set a blank form for create mode having a save and cancel buttons, a data populated form in the edit mode having an update and cancel buttons and again data populated form in the delete mode having an delete and cancel buttons.

    I want to achieve this using a single class which extends from MultiActionController and If I use a single MultiActionController class where do I call setBindOnNewForm(true). I cannot call it (setBindOnNewForm(true)) if I am going for a new entry.

    I am speaking something related to Struts DispatchAction Class. In the petstore application there are seperate classes for Save and Edit Operations and I dont want to follow that model.

    suggestions invited.....

  • #2
    You can have a SimpleFormController with in the URL a parameter m=create/update/delete and then in the Controller add code like this:

    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    String method = RequestUtils.getRequiredStringParameter(request, RequestConstants.METHOD);
    if (method.equals(SAVE)) {
    ....
    } else if (method.equals(DELETE)) {
    ....
    }
    }

    Cheers, Stefaan.

    Comment


    • #3
      I wouldn't use a MultiActionController for handling forms, SimpleFormController is generally much better suited.

      The issue with trying to use Stefaan's technique with multiple submit buttons is that it relies on all the buttons having the same name (which would be 'method' or whatever), and then the value is going to be the actual text that is displayed to the user. But this is somewhat of a drag to check for, as in an internationalized app, the actual value will be different for every language. The controller should not really be dependent on the the value.

      Much better I think is to make every submit button have a unique name, then they will come in as three different parameters, where the value is the display text and can be ignored. Then just check for the one that is non-null:

      if (RequestUtils.getStringParameter(request, SAVE, null) != null) {
      ....
      } else if (RequestUtils.getStringParameter(request, DELETE, null) != null)
      ...

      etc.

      If you want to get fancier, you can instead in your command class define the commands as String properties, and see if one of them is set, but I'm not sure this is that much cleaner (except you don't need to touch the request), and you need to be careful to reset them when using SessionForms...

      Comment


      • #4
        or you could have ordinarily buttons (or hrefs with or without images) that will update a hidden field on the form indicating what kind of action was requested. This way you can have multiple actions on a page resulting in different actions on the server, especially if the webcontroller supports this, which (of course) is exactly what www.competities.com/springworkflow does for you (cough, I will stop my plugging of this framework now, just couldnt resist it :mrgreen:

        Comment

        Working...
        X