tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tapestry-...@jakarta.apache.org
Subject [Jakarta Tapestry Wiki] New: FrequentlyAskedQuestions/SubmitListener
Date Thu, 03 Jun 2004 19:15:29 GMT
   Date: 2004-06-03T12:15:29
   Editor: HowardLewisShip <hlship@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

View raw message