我有两个viewParameters和两个绑定到bean属性的inputTexts。
当我加载该页面时(通过在浏览器中输入URL),在RESTORE_VIEW阶段期间,viewParameters的setter将被调用两次。
在RENDER_RESPONSE中调用inputTexts的setter一次
为什么viewParameters的setter会被调用两次?
为什么不同UI组件的setter会在完全不同的阶段被调用?
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>
豆子:
@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");
}
}
输出(相位信息来自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