简体   繁体   English

从SelectManyListBox获取选定的标签

[英]Get selected labels from SelectManyListBox

I want to get value and label of the selected items of a h:selectManyListbox . 我想获取h:selectManyListbox的选定项目的值标签。

I've this: 我有这个:

<h:selectManyListbox id="myList" size="10" value="#{search.selectedItems}">
    <f:selectItems id="myListID" value="#{search.itemsList}">
</h:selectManyListbox>

The problem is that when I submit the form I get only the a List<String> value and I need both: values and labels selected. 问题是,当我提交表单时,我仅获得一个List<String>值,并且我同时需要:选择值和标签。

How can I get this? 我怎么能得到这个?

You can't. 你不能 HTML won't send the option label to the server side. HTML不会将选项标签发送到服务器端。 Besides, you normally already know the label associated with the value in the server side. 此外,您通常已经知道服务器端与该值关联的标签。 Just have some mapping of label-value pairs (eg Map<String, String> ) so that you can obtain the associated label by the selected value (even more, you can reuse the map in <f:selectItems> ). 只是具有一些标签-值对的映射(例如Map<String, String> ),以便您可以通过所选值获得关联的标签(甚至更多,您可以在<f:selectItems>重用该映射)。

That said, the need to know the label is a design smell. 就是说,需要知道标签是一种设计气味。 Shouldn't this information go in the value in first place (as well)? 此信息也不应放在第一位吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM