[英]How can I get item label from selectOneMenu @ JSF page
I'm dealing with a wizard in primefaces like this one: 我正在处理像这样的素数面向导:
http://www.primefaces.org/showcase/ui/wizard.jsf http://www.primefaces.org/showcase/ui/wizard.jsf
I would like to get the raw text from a selectOneMenu (from one of the tabs) and show it in the confirmation tab. 我想从selectOneMenu(从其中一个选项卡)获取原始文本并在确认选项卡中显示它。
My selectOneMenu looks like this: 我的selectOneMenu看起来像这样:
<p:selectOneMenu id="vinculos"
value="#{socioAdicional.idVinculo}" required="true"
label="Vinculo">
<f:selectItem itemLabel="#{mensajes.combos_empty_txt}" itemValue="#{null}" />
<f:selectItems value="#{controladorCombos.vinculos}"
var="vinculo" itemLabel="#{vinculo.descripcion}"
itemValue="#{vinculo.id}" />
</p:selectOneMenu>
All the values are obtained from a webservice and can't be stored in an map attribute, cause we are using other buffering strategies... 所有值都是从Web服务获取的,不能存储在map属性中,因为我们正在使用其他缓冲策略......
I've tried so far to print that text (on a different tab) like this: 到目前为止,我已尝试打印该文本(在不同的标签上),如下所示:
<b>Vinculo: </b><h:outputText value="#{p:component('vinculos').getSelectedValue()}"/>
Any ideas? 有任何想法吗?
Thanks! 谢谢!
Either use a Map<ItemId, Item>
as available items, so that you can get the whole Item
at hands based on the selected item ID: 无论是使用
Map<ItemId, Item>
的可用项目,这样就可以得到整个Item
的基础上,选择的项目ID手:
private Long selectedItemId;
private Map<Long, Item> availableItems;
<h:selectOneMenu value="#{bean.selectedItemId}">
<f:selectItems value="#{bean.availableItems.values()}" var="item"
itemValue="#{item.id}" itemLabel="#{item.description}" />
</h:selectOneMenu>
...
<b>Selected item:</b> #{bean.availableItems[bean.selectedItemId].description}.
Or use whole Item
instead of Id
as selected item, with a converter, so that you immediately already have the whole Item
at hands: 或者使用整个
Item
代替Id
作为选定项目,使用转换器,这样您就可以立即拥有整个Item
:
private Item selectedItem;
private List<Item> availableItems;
<h:selectOneMenu value="#{bean.selectedItem}" converter="itemConverter">
<f:selectItems value="#{bean.availableItems}" var="item"
itemValue="#{item}" itemLabel="#{item.description}" />
</h:selectOneMenu>
...
<b>Selected item:</b> #{bean.selectedItem.description}.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.