如何使用Primefaces在Bean中向HashMap输入值? [英] How to input values to HashMap in bean using Primefaces?

查看:55
本文介绍了如何使用Primefaces在Bean中向HashMap输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我必须在其中使用键值对关联两个字段并保存.例如,我有许多participant,谁拥有price.如果我使用两个p:inputText字段输入它们的值,那么后备bean应该是什么样子?

I have a page where I have to associate two fields using key-value pair and save. For example, I have a number of participants who has prices. If I use two p:inputText fields to enter their values, how should the backing bean look like?

此外,我想根据我输入的参与者数量来显示这样的p:inputText字段对的数量.我在这里回答了类似的问题如何动态插入素数输入文本?.但是我希望能够将这些值提交给键值对.

Also, I want to display the number of such pairs of p:inputText fields according to the number of participants I enter. I have a similar question answered here How to insert a primefaces input text dynamically?. But I want to be able to submit the values to a key-value pair.

推荐答案

在EL中,您可以将映射与实体/模型bean完全一样地对待.

In EL, you can treat maps exactly the same way as entity/model beans.

<h:inputText value="#{bean.map.key1}" />
<h:inputText value="#{bean.map.key2}" />
<h:inputText value="#{bean.map.key3}" />

此示例将输入值放在映射键key1key2key3下.

This example will put the input values under map keys key1, key2 and key3.

注意:确保地图不是null.与普通实体/模型Bean一样,JSF/EL不会为您预先创建它.自己在@PostConstruct中完成.

Note: make sure that the map isn't null. Like as with normal entity/model beans, JSF/EL won't precreate it for you. Do it in the @PostConstruct yourself.

这篇关于如何使用Primefaces在Bean中向HashMap输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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