如何设置< h:inputText>的提交值在< ui:repeat>内部进入地图,集合或列表 [英] How to set submitted values of <h:inputText> inside <ui:repeat> into map, set or list
问题描述
我想知道是否可以将<ui:repeat>
内部的值推送到地图,集合或列表吗?
I would like to know if it possible to push a value from inside a <ui:repeat>
to a map, a set or a list?
我想将<h:inputtext>
的值传递给集合.
I would like to pass the value of the <h:inputtext>
to a set.
代码:
<ui:repeat var="_par" value="#{cmsFilterParameterHandler.normaleSuchParameter()}">
<p:outputLabel value="#{_par.bezeichnung}" />
<p:spacer width="5px" />
<p:inputText id="me" value="#{??? push me to a set ???}"/>
<br /><br />
</ui:repeat>
推荐答案
对于Set
,它是不可能的,因为它不允许按索引或键引用项目.但是,只需在输入值中指定列表索引和映射键,就可以使用List
和Map
.
With a Set
, it is not possible as it doesn't allow referencing items by index or key. It's however possible with a List
and a Map
by just specifying the list index and map key in the input value.
使用List
:
private List<String> list; // +getter (no setter necessary)
@PostConstruct
public void init() {
list = createAndFillItSomehow();
}
<ui:repeat value="#{bean.list}" varStatus="loop">
<h:inputText value="#{bean.list[loop.index]}" />
</ui:repeat>
With a Map
(only if your environment supports EL 2.2 or JBoss EL):
private Map<String, String> map; // +getter (no setter necessary)
@PostConstruct
public void init() {
map = createAndFillItSomehow();
}
<ui:repeat value="#{bean.map.entrySet().toArray()}" var="entry">
<h:inputText value="#{bean.map[entry.key]}" />
</ui:repeat>
请注意,规范方法是使用完全有价值的Javabeans List
.假设具有属性id
和value
的名为Par
的Javabean类准确地映射到DB中具有列id
和value
的par
表:
Noted should be that the canonical approach is to use a List
of fullworthy javabeans. Let's assume a Javabean class named Par
with properties id
and value
which maps exactly to a par
table in DB with columns id
and value
:
private List<Par> pars; // +getter (no setter necessary)
@PostConstruct
public void init() {
pars = createAndFillItSomehow();
}
<ui:repeat value="#{bean.pars}" var="par">
<h:inputText value="#{par.value}" />
</ui:repeat>
无论哪种方式,它在使用<p:inputText>
时都可以很好地工作,它与PrimeFaces毫无关系,在这个问题的上下文中,它仅仅是一个基于jQuery的JSF UI组件库.只需将h:
替换为p:
即可将其打开.
Either way, it works as good when using <p:inputText>
, it's in no way related to PrimeFaces, it's in the context of this question merely a jQuery based JSF UI component library. Just replace h:
by p:
to turn it on.
这篇关于如何设置< h:inputText>的提交值在< ui:repeat>内部进入地图,集合或列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!