Dealing with multiple submits

If you want to have two or more submits on a form with different actions (e.g. different pages to invoke) you can do the following:

  1. add the two submit buttons to the form
    @Component
    private Submit submit1;
    
    @Component
    private Submit submit2;
  2. add event listeners for “select” event on both buttons and save the return value the form action should return on success:
    private Object formEventReturn;
    
    void onSelectFromSubmit1() {
      // do whatever;
      formEventReturn = AnotherPage.class; // go to AnotherPage
    }
    
    void onSelectFromSubmit2() {
      // do whatever
      formEventReturn = null; // stay on this page
    }
  3. in the event from the form return the formEventReturn
    Object onSuccessFromFoo() {
      // do things specific to form Foo
      return formEventReturn;
    }

All this has to be done because the Submit cannot add a context to the form and the “select” events must not return any objects (just void). The idea for this solution is from HLS (see HLS on mailing-list about multiple submits)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s