问题
I have rendered checkboxes and I have rendered selected checkboxes values like below:
<h:selectManyCheckbox id="chkedition" value="#{adcreateBean.selectedEditions}" layout="lineDirection" styleClass="nostyle">
<f:selectItems value="#{adcreateBean.editions}" var="item" itemLabel="#{item.editionName}" itemValue="#{item.editionID}"/>
<p:ajax update="dt1" />
</h:selectManyCheckbox>
<h:dataTable id="dt1" value="#{adcreateBean.selectedEditions}" var="it" styleClass="nostyle" width="100%">
<f:facet name="header">
<h:outputText value="You have selected :" />
</f:facet>
<h:column>
<h:outputText value="#{it}" />
</h:column>
</h:dataTable>
My problem is, it displays id of selected value. But I want name(label) of selected value . So what should I do?
回答1:
Your itemValue indeed only passes the edition ID. You need to pass the edition name instead.
<f:selectItems value="#{bean.editions}" var="edition"
itemLabel="#{edition.name}" itemValue="#{edition.name}"/>
Or, just pass the whole Edition object.
<f:selectItems value="#{bean.editions}" var="edition"
itemLabel="#{edition.name}" itemValue="#{edition}"/>
You'll only need to create a custom Converter which converts between Edition and String.
来源:https://stackoverflow.com/questions/11066083/how-to-get-name-of-the-selected-checkbox-value-from-id