NOTE: This is outdated information that applies only to Tapestry 4.

So, you have a Submit component and other components in a page, something like:

  <input jwcid="@Submit" listener="ognl:listeners.performOperation" label="Execute"/>

  <select jwcid="@PropertySelection" value="ognl:selectedValue" model="ognl:valueModel"/>

Problem: when the user clicks your Submit button, the selectedValue property will not have been updated yet, because it occurs later in the template.

What we want is a way to defer the execution of the Submit's listener until the entire form has been processed.

Here's a recipe that works in Tapestry 3.0.

In the page specification define a new property:

  <property-specification name="submitListener" type="org.apache.tapestry.IActionListener"/>

Change the Submit component in the HTML template to:

  <input jwcid="@Submit" selected="ognl:submitListener" tag="ognl:listeners.performOperation"/>

This causes the Submit button to assign the value of expression listeners.performOperation to property submitListener when the button is clicked. The rewind of the form continues, giving the other components a chance to rewind.

Lastly, your form's listener method needs some changes:

public abstract IActionListener getSubmitListener();

public void formSubmit(IRequestCycle cycle)
{
  IActionListener submitListener = getSubmitListener();

  if (submitListener != null)
    submitListener.actionTriggered(null, cycle);

  . . .

This gets the listener identified by the Submit button and executes its listener method. You might have many different Submit and ImageSubmit components on your page, but only one of them will be activated, so they can all share the single submitListener property.

FrequentlyAskedQuestions/SubmitListener (last edited 2011-01-02 02:06:55 by BobHarner)