1

I am following this to understand the JSF lifecycle. I would like to check if my understanding is correct on JSF immediate="true" attribute in various cases as mentioned below. I tried these cases with simple JSF form and a bean.

Case 1: Immediate="true" on commandButton

<h:form>
        <table>
            <tr>
              <td><h:outputLabel value="Name"/></td>
              <td><h:inputText value="#{userLogin.name}"/></td>
            </tr>
            <tr>
              <td><h:outputLabel value="Password"/></td>
              <td><h:inputText value="#{userLogin.password}"/></td>
            </tr>
            <tr> 
              <td><h:commandButton value="Sign In" action="#{userLogin.saveData}" immediate="true"/></td>
            </tr>
        </table>
    </h:form>

It directly invokes application i.e., executes saveData action method without any form processing. And this activity is done in Apply Request Values lifecycle phase. The phases like Process Validations, Update Model values, Invoke application are skipped.

Case 2 : Immediate="true" on inputText

<h:form>
        <table>
            <tr>
              <td><h:outputLabel value="Name"/></td>
              <td><h:inputText value="#{userLogin.name}" required="true" immediate="true"/></td>
            </tr>
            <tr>
              <td><h:outputLabel value="Password" required="true"/></td>
              <td><h:inputText value="#{userLogin.password}"/></td>
            </tr>
            <tr> 
              <td><h:commandButton value="Sign In" action="#{userLogin.saveData}"/></td>
            </tr>
        </table>
    </h:form>

Form will not be submitted when any of the fields are left empty. That mean validation is happening for field with immediate="true" and the other field without immediate attribute set, both the values are updated in model. What is the difference, how to understand this? Does the validation happens on priority for the input field with immediate attribute in Apply request values phase and validation happens for the second input field without immediate attribute in Process Validations phase?

Case 3 : Immediate="true" on inputText and commandButton

<h:form>
        <table>
            <tr>
              <td><h:outputLabel value="Name"/></td>
              <td><h:inputText value="#{userLogin.name}" required="true" immediate="true"/></td>
            </tr>
            <tr>
              <td><h:outputLabel value="Password" required="true"/></td>
              <td><h:inputText value="#{userLogin.password}"/></td>
            </tr>
            <tr> 
              <td><h:commandButton value="Sign In" action="#{userLogin.saveData}" immediate="true"/></td>
            </tr>
        </table>
    </h:form>

Form is submitting with empty values also, meaning its not validating, the action method is executed, and I see that the model values are also not updated when entered during submission. Hence all the phases like Process Validations, Update model values, invoke application are skipped despite the action method is called in Apply Request Values phase.

I am not so sure if my understanding is correct.

srk
  • 4,857
  • 12
  • 65
  • 109

0 Answers0