How to get name of the selected checkbox value from id?

与世无争的帅哥 提交于 2019-12-11 20:48:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!