0

I have two viewParameters and two inputTexts bound to a bean property.

When I load that page (by entering the URL in the browser) the setters for the viewParameters get called twice each during the RESTORE_VIEW phase.

The setters for the inputTexts get called once in the RENDER_RESPONSE

Why do the setter for viewParameters get called twice?

Why do the setters for different UI components get called in completely different phases?

Body of the xhtml:

<h:body>
    <h:form
      id="modelSearch">


<f:metadata>
   <f:viewParam name="one" binding="#{modelSearchBean.requestOne}" > </f:viewParam>
   <f:viewParam name="two" binding="#{modelSearchBean.requestTwo}" />
</f:metadata>

      <p:messages display="text" />

                  <p:outputLabel
                    for="one"
                    value="one" />
                  <p:inputText
                    id="one"
                    binding="#{modelSearchBean.one}"
                    >
                  </p:inputText>

                  <p:outputLabel
                    for="two"
                    value="two" />
                  <p:inputText
                    id="two"
                    binding="#{modelSearchBean.two}"
                    >
                  </p:inputText>
    </h:form>
</h:body>

The bean:

@Component("modelSearchBean")
@Scope("request")
public class ModelSearchBean {

    private UIInput requestOne;
    private UIInput requestTwo;
    private UIInput one;
    private UIInput two;

    public UIInput getRequestOne() {
        return requestOne;
    }

    public void setRequestOne(UIInput requestOne) {
        this.requestOne = requestOne;
        System.out.println("requestOne");
    }

    public UIInput getRequestTwo() {
        return requestTwo;
    }

    public void setRequestTwo(UIInput requestTwo) {
        this.requestTwo = requestTwo;
        System.out.println("requestTwo");
    }

    public UIInput getOne() {
        return one;
    }

    public void setOne(UIInput one) {
        this.one = one;
        System.out.println("One");
    }

    public UIInput getTwo() {
        return two;
    }

    public void setTwo(UIInput two) {
        this.two = two;
        System.out.println("two");
    }
}

Output (the Phase information comes from a PhaseListener):

>>>>>> STARTING PHASE: RESTORE_VIEW 1
requestOne
requestTwo
requestOne
requestTwo
<<<<<< ENDING PHASE: RESTORE_VIEW 1
>>>>>> STARTING PHASE: APPLY_REQUEST_VALUES 2
<<<<<< ENDING PHASE: APPLY_REQUEST_VALUES 2
>>>>>> STARTING PHASE: PROCESS_VALIDATIONS 3
<<<<<< ENDING PHASE: PROCESS_VALIDATIONS 3
>>>>>> STARTING PHASE: UPDATE_MODEL_VALUES 4
<<<<<< ENDING PHASE: UPDATE_MODEL_VALUES 4
>>>>>> STARTING PHASE: INVOKE_APPLICATION 5
<<<<<< ENDING PHASE: INVOKE_APPLICATION 5
>>>>>> STARTING PHASE: RENDER_RESPONSE 6
One
two
<<<<<< ENDING PHASE: RENDER_RESPONSE 6
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • This explanation about the [different behaviour between taghandlers and UI Components](http://stackoverflow.com/a/3343681/1353722) might help. – lefloh May 23 '14 at 11:02
  • @lefloh interesting answer, but viewParameter and inputText are both UI Input components, so they should behave the same as far as I can understand. – Jens Schauder May 23 '14 at 12:50

0 Answers0