2013-02-01 72 views
0

命令爲什麼以下工作:號碼:內部轉盤

<h:form id="form1"> 
<p:carousel id="carousel" value="#{galleriaBean.paths_tn}" var="img" itemStyle="width: 200px"> 
<p:graphicImage value="#{img}"/> 
</p:carousel> 

<p:commandLink id="here" value="click me" update="hello11" oncomplete="dlg.show()"> 
<f:setPropertyActionListener value="hello!!!" target="#{galleriaBean.selected}"/> 
</p:commandLink> 

<p:dialog widgetVar="dlg"> 
<h:outputText id="hello11" value="#{galleriaBean.selected}"/> 
</p:dialog> 
</h:form> 

但移動commandLink進入旋轉木馬,它不工作? setPropertyActionListener甚至沒有在bean中設置變量。

@RequestScoped CDI Bean。

<p:carousel id="carousel" value="#{galleriaBean.paths_tn}" var="img" itemStyle="width: 200px"> 
<p:graphicImage value="#{img}"/> 
<p:commandLink id="here" value="click me" update=":form1:hello11" oncomplete="dlg.show()"> 
<f:setPropertyActionListener value="#{img}" target="#{galleriaBean.selected}"/> 
</p:commandLink> 
</p:carousel> 
+1

你的支持bean的範圍是什麼? – partlov

+0

@RequestedScope – jacktrades

+0

嘗試@ViewScope,看看發生了什麼。 – partlov

回答

2

你並沒有顯示你的代碼的第二個版本(當你把p:commandLinkp:carousel),但我想,你的推杆內的p:commandLinkvalue屬性後臺bean的某些屬性。您必須意識到AJAX請求也是請求,因此您請求有範圍的bean將在每個AJAX請求中重新創建。爲了保存你在f:setPropertyActionListener中使用的財產狀態,你必須讓你的bean至少可以查看範圍,或者以某種方式保留@PostConstructor方法中的狀態。如果你可以使用視圖範圍的bean,那應該完成。

+0

在第二個版本代碼中,有趣的是它不會在@RequestScoped bean上調用setter方法..這很奇怪。它確實被創建並銷燬。 – jacktrades