You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ta...@jakarta.apache.org on 2004/06/03 21:15:29 UTC

[Jakarta Tapestry Wiki] New: FrequentlyAskedQuestions/SubmitListener

   Date: 2004-06-03T12:15:29
   Editor: HowardLewisShip <hl...@apache.org>
   Wiki: Jakarta Tapestry Wiki
   Page: FrequentlyAskedQuestions/SubmitListener
   URL: http://wiki.apache.org/jakarta-tapestry/FrequentlyAskedQuestions/SubmitListener

   no comment

New Page:

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.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org