[英]How to input values to HashMap in bean using Primefaces?
I have a page where I have to associate two fields using key-value pair and save. 我有一个页面,我必须在其中使用键值对关联两个字段并保存。 For example, I have a number of
participant
s who has price
s. 例如,我有许多
price
为的participant
。 If I use two p:inputText
fields to enter their values, how should the backing bean look like? 如果我使用两个
p:inputText
字段输入它们的值,那么后备bean应该是什么样?
Also, I want to display the number of such pairs of p:inputText
fields according to the number of participants I enter. 另外,我想根据我输入的参与者数量来显示
p:inputText
字段对的数量。 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.
但我希望能够将值提交给键值对。
In EL, you can treat maps exactly the same way as entity/model beans. 在EL中,可以将映射与实体/模型Bean完全一样地对待。
<h:inputText value="#{bean.map.key1}" />
<h:inputText value="#{bean.map.key2}" />
<h:inputText value="#{bean.map.key3}" />
This example will put the input values under map keys key1
, key2
and key3
. 本示例将输入值放在映射键
key1
, key2
和key3
。
Note: make sure that the map isn't null
. 注意:确保地图不为
null
。 Like as with normal entity/model beans, JSF/EL won't precreate it for you. 与普通实体/模型Bean一样,JSF / EL不会为您预先创建它。 Do it in the
@PostConstruct
yourself. 自己在
@PostConstruct
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.