如何从ID获取所选复选框值的名称?

问题描述:

我已经渲染了复选框,并且已经渲染了选中的复选框值,如下所示:

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> 

我的问题是,它显示所选值的ID.但是我想要选定值的名称(标签).那我该怎么办?

My problem is, it displays id of selected value. But I want name(label) of selected value . So what should I do?

您的itemValue实际上仅传递版本ID.您需要改为传递版本名称.

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}"/>

或者,只需传递整个Edition对象.

Or, just pass the whole Edition object.

<f:selectItems value="#{bean.editions}" var="edition" 
    itemLabel="#{edition.name}" itemValue="#{edition}"/>

您只需要创建一个自定义的Converter即可在EditionString之间进行转换.

You'll only need to create a custom Converter which converts between Edition and String.