Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immediate="true" causes update="component" to fail

I have a command button (a Cancel button to be specific) that I want to bypass the validation of some components on my page. When I have immediate="true" set on my command button, the update attribute does not work. By "not work" I mean that the values on :centerForm:p_definition do not reset to what they should be. If I select an item from a dropdown or enter data into an input text, the information should disappear when clicking cancel. Setting immediate="false" or leaving it off completely does reset the fields as expected. Here is the definition of the commandbutton I am having trouble with.

<p:commandButton value="Cancel" style="float: right;"
    immediate="true"
    actionListener="#{manageBomPropHandler.doCancel()}"
    update=":centerForm:p_definition"/>

Is that the expected behavior from immediate="true"? If so, how have you gotten around this for cancel buttons?

like image 934
SteveS Avatar asked Dec 28 '12 21:12

SteveS


2 Answers

"Update" will be called/executed at Update Model Value phase. When you set "immediate" attribute to button command, this phase is ignored.See below images for more detail. Standard Lifecycle executes Update Model Values phase

          P1: Standard Lifecycle executes Update Model Values phase

Immediate Lifecycle ignored Update Model Values phase

          P2: Immediate Lifecycle ignored Update Model Values phase
like image 101
Ken Block Avatar answered Oct 12 '22 23:10

Ken Block


If may help, there's a already solution for clean input fields with primefaces:

<p:commandButton value="Reset Tag" update="panel" process="@this" style="margin-right:20px;" >
    <p:resetInput target="panel" />
</p:commandButton>

OR

<h:commandButton value="Reset p:ajax" style="margin-right:20px;" >
    <p:ajax update="panel" resetValues="true" />
</h:commandButton>

Source: http://www.primefaces.org/showcase/ui/misc/resetInput.xhtml

like image 43
Mr. Anderson Avatar answered Oct 12 '22 23:10

Mr. Anderson