2014-01-10 43 views
0

我正在使用Primefaces和JSF來開發此前端。我的問題是,我的一個selectonemenus從來沒有設置它的值綁定,「selectedGroup」,所以第二個下拉列表從不填充。我的支持bean被調用來「更新」第二個selectonemenu,但是這個ajax的監聽器沒有被調用,也沒有設置selectedGroup。該代碼實際上與"Select"的Showcase相同。我甚至證實了展示代碼從頭開始工作(我沒有懷疑),但沒有看到我的情況與這個例子有什麼不同。Primefaces/JSF:selectOneMenu值未設置,ajax偵聽器未調用

有關此主題的其他計算器問題表明某些內容已被排除,但這些建議都不符合我的問題。

我有兩個selectOneMenus,就像這樣。

<h:form id="outerForm"> 

    <p:panel id="outerPanel"> 

     <p:panelGrid id="outerPanelGrid"> 
      <h:outputLabel for="groupSelection" value="Group: "/> 
      <p:selectOneMenu id="groupSelection" value="#{myBean.selectedGroup}" > 
       <p:ajax update="commandSelection" 
         listener="#{myBean.handleGroupSelection}" /> 
       <f:selectItem itemLabel="---Please Select Group---" itemValue=""/> 
       <f:selectItems var="group" value="#{myBean.groups}" 
           itemLabel="#{group.name}" itemValue="#{group.name}" /> 
      </p:selectOneMenu> 

      <h:outputLabel for="commandSelection" value="Command: "/> 
      <p:selectOneMenu id="commandSelection" value="#{myBean.command}"> 
       <f:selectItems value="#{myBean.commandStringsList}"/> 
      </p:selectOneMenu> 
     </p:panelGrid> 
    </p:panel> 
</h:form> 

此頁面所顯示的一樣,所以我的佈局模板的「中心」部分..

<ui:define id="content" name="content"> 
    <p:panel id="contentPanel" style="float:left; border:none"> 
     <ui:include src="#{anotherBean.currentView}.xhtml"/> 
    </p:panel> 
</ui:define> 

的支持bean確實使用了一些數據類包含一些其中填充數據,但我認爲我正在盡一切努力將其映射到視圖中。不過,大多數情況下,我使用的是字符串。

有沒有人看到我失蹤?至少,這個xhtml是否有效?

我還應該提到,在創建和使用模板之前,此頁面正在工作。基本上,我使用ui:include在index.xhtml的主體中將其呈現在TabView的選項卡中。雖然我最初沒有注意到,但是在我加入模板之後的某個時候,這個頁面停止了工作(我知道我的測試很差)。

+0

只是爲了澄清:你的表單ID是outerForm。你還沒有嵌套形式,對吧? – 757071

+0

正確,ui:define存在於ui:composition中,並且模板佈局也不包含任何表單。 – ThatsAMorais

+0

通過http://stackoverflow.com/a/2120183/757071和http://stackoverflow.com/a/16125396/757071,答案中的要點可能會有所幫助。 – 757071

回答

0
<f:selectItems var="group" value="#{myBean.groups}" 
    itemLabel="#{group.name}" itemValue="#{group.name}" /> 

你不能用這種方式指定selectItems。翻譯必須是雙向的。使用轉換器!

<f:selectItems var="group" value="#{myBean.groups}" 
    itemLabel="#{group.name}" itemValue="#{group}" 
    converter="groupConverter"/> 
+0

只有OP不需要'#{group}',他希望'#{group.name}'看起來像是'String':不需要轉換 – kolossus

+0

正確,kolossus,group是一個String。即使是現在,在將所有最近的更改存儲到單獨的分支並重置主管之後,我仍然無法知道發生了什麼,並緩慢地添加了我想要的更改。這樣做後,我設法不再遇到這個問題。 – ThatsAMorais

+0

'#{myBean.selectedGroup}'是一個字符串嗎? (不是'selectedGroupName'是一個更好的標識符?) –

相關問題