如何从ID获取所选复选框值的名称? [英] How to get name of the selected checkbox value from id?

查看:404
本文介绍了如何从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.

这篇关于如何从ID获取所选复选框值的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆