myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "ClearInputComponents" by SimonKitching
Date Fri, 26 Jan 2007 01:27:03 GMT
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:

Mime
View raw message