DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Webwork2 Multiple Buttons In Form

04.12.2005
| 5028 views |
  • submit to reddit
        To react on multiple buttons in webforms use the following if you don't want to depend on the value attribute of the button (think of i18n):
<form>
<input name="foo">
<input type="submit" name="buttonAction.ok" value="submit">
<input type="submit" name="buttonAction.cancel" value="cancel">

And in the action:
class FooAction implements Action {
    private Map buttonAction = new HashMap();
    public Map getButtonAction() { return buttonAction; }

    public String execute() {
        if(buttonAction.containsKey("ok") {
          // ok was pressed
        } else if (buttonAction.containsKey("cancel") {
          // cancel was
        } else {
          // no button was pressed (enter key?)
        }
        ...
    }
}