Simon,
I noticed a probable mistake in the following line from your addition:
+ However when using command components with immediate=false, things
become more complex.
Here you are actually talking about the scenario immediate=true! You
described immediate=false in a previous paragraph. I have made this
change already for you on the wiki, but if I am mistaken please revert
it. :)
Regards,
Jeff Bischoff
Kenneth L Kurz & Associates, Inc.
Mike Kienenberger wrote:
Simon,
Since you're working on this page, can you please remove this part at
the bottom of the page? I've successfully used the "return non-null
navigation outcome to the same page" in order to reset form values.
Note that this approach has not been tested; if you find it does work,
then please update this page.
On 1/25/07, Apache Wiki <[EMAIL PROTECTED]> wrote:
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Myfaces Wiki"
for change notification.
The following page has been changed by SimonKitching:
http://wiki.apache.org/myfaces/ClearInputComponents
------------------------------------------------------------------------------
+ === Problem Description ===
+
Sometimes you want to provide a command component (eg a link or
button) that performs some server action, and
- renders the same page but with completely "fresh" values for all
components. However this doesn't work well
+ renders the same page but with completely "fresh" values for all
components.
- when the component is "immediate"; in this case input components get
their "submitted value" set during the postback
- and re-render that submitted value even when the backing values for
those input components have been reset to default values.
+ When using command components with the normal immediate setting
(false), achieving this is just a matter of clearing the beans that
the JSF component value attributes access. Any values entered by the
user will have been pushed into these beans as part of the Update
Model phase, so the components themselves will not be holding any
information about submitted data. The action method associated with
the command is then run which resets the model, and when the
components render themselves they will draw fresh data from the
(reset) beans.
+
+ Note that because data is being pushed into the model, the
validation phase must run, and therefore any invalid data in the page
will cause the action to be skipped, and the page is redisplayed with
the validation errors displayed. This is not generally the desired
behaviour for a "clear" type operation! The solution is to set
attribute immediate=true on the command so that its associated action
is invoked before validation is applied to the input components in the
same view (see ["How_The_Immediate_Attribute_Works"]).
+
+ However when using command components with immediate=false, things
become more complex. All components will retrieve the raw submitted
values submitted by the user, but the immediate command will then run
before they can be pushed into the backing beans; the components
therefore remember this data. When the (immediate) action causes
navigation to another view then this is no problem; these components
will be discarded anyway. However if the action method causes JSF to
go directly to the render phase 'of the same view' [by calling
facesContext.renderResponse()], then the components will behave as
they do for a validation failure - by displaying the value cached in
the component rather than fetching data from the backing bean.
+
- Here are a number of possible solutions
+ Below are a number of possible solutions.
=== Force a new View ===
Call this method from the action method of the immediate command
component: