Monday, February 8, 2010

The ADF Faces RC: <af:resetActionListener/> tag works like magic!

I can't imagine that my half-day of debugging on how to reset the input components in my form to original value will be solved by a single tag, and that is:

Below is an excerpt from the JDeveloper help:
The resetActionListener tag is a declarative way to allow an action source (<commandbutton>, <commandlink>, etc.) to fire a reset action. All values submitted will be reset to null or empty. The reset will not alter any model state directly, rather the enclosing action should have its own actionListener which will reset all model values to their defaults. The resetActionListener tag supports no attributes.
This example shows a "Reset..." button. When the button is pressed, all elements on the form will be reset before being applied. The resetModel actionListener will also be called.
<af:commandButton id="reset"
Attributes: None.
In our case, we have a form which is initially displayed as read-only. Invoking Edit button will enable the input components for user edit. Once the the user decided to cancel his edits, he will press the Cancel button and the input components should revert back to their original values.
Below is a snippet from our .jsff page:
<af:commandToolbarButton text="Cancel" id="cb2"
Below is the sample method that resets our model:
public void cancel(ActionEvent actionEvent) {
        getPageFlowScope().put("editMode", false);


  1. by, same tone

    in a the user is going to insert a row . so he press insert button.but he didnt enter anything in the row. but he decide cancel the created row.

    this my scenario. what i want do? please guide me.

  2. @Subu
    The given solution also works for your case. try it.