0
我正在一個客戶資料頁面上有不同的元素, h:selectOneMenu
,h:selectOneRadio
,h:selectBooleanCheckbox
,h:selectManyCheckbox
,其使用List<MasterDTO>
使用來自數據庫的主值填充。當頁面處於編輯模式時,元素顯示完美。但是,當頁面更改爲查看模式時,將顯示選定的項目標籤,而不是顯示所選的項目標籤。例如。需要在查看模式下將Single
顯示爲Marital Status
,而不是顯示001
。顯示項目標籤爲下拉列表,單選按鈕,許多複選框和布爾複選框,而不是項目值
請參考下面的示例代碼。我不想在所有代碼中將List
對象更改爲諸如Map<K,V>
之類的東西。我正在使用JSF 2.0和Primefaces 3.4.2。有沒有解決方案?
選擇一個菜單
<h:selectOneMenu id="marital_status" style="width:178px;"
rendered="#{customerProfileBean.editMode}"
value="#{customerProfileBean.marital_status}">
<f:selectItem itemValue="-1" itemLabel="--- Select ---" />
<f:selectItems value="#{customerProfileBean.maritalStatusList}"
var="mst" itemLabel="#{mst.valueName}" itemValue="#{mst.valueCode}" />
</h:selectOneMenu>
<h:outputText rendered="#{not customerProfileBean.editMode}"
value="#{customerProfileBean.marital_status}" />
選擇多個複選框
<h:selectManyCheckbox id="loanTypes" styleClass="selectOptionSpace"
rendered="#{customerProfileBean.editMode}"
value="#{customerProfileBean.loanTypes}">
<f:selectItems value="#{customerProfileBean.creditFacList}"
var="mst" itemLabel="#{mst.valueName}" itemValue="#{mst.valueCode}" />
</h:selectManyCheckbox>
<h:outputText rendered="#{not customerProfileBean.editMode}"
value="#{customerProfileBean.custLoanType}" />
這不是黃素相關。你只是在你的例子中使用jsf。 Primefaces將是p:selectOneMenu和p:selectManyCheckbox。你的primefaces版本完全過時btw。最新的社區版本是6.0。 – lastresort
您似乎在maritalStatusList中的項目的valueName屬性中有'標籤'。所以一個簡單的Java方法來顯示這個基於marital_status值將解決你的問題...有效地甚至不jsf相關... – Kukeltje