从< ui:repeat>内推出一个值在地图,设置或列表中 [英] Pushing a value from inside <ui:repeat> in a map, set or list
问题描述
我想知道是否可以将值从里面推到地图,集合或列表?
我想传递值的输入文字到一组。
代码:
ui:repeat var =_ parvalue =#{cmsFilterParameterHandler.normaleSuchParameter()}>
< p:outputLabel value =#{_ par.bezeichnung}/>
< p:spacer width =5px/>
< p:inputText id =mevalue =#{??? push me to a set ???}/>
< br />< br />
< / ui:repeat>
Regards
Markus
使用 Set
,这是不可能的,因为它不允许通过索引或键引用项目。只需在输入值中指定列表索引和地图键,就可以使用列表
和 Map
/ p>
使用列表
:
private List< String>列表; // + getter(不需要setter)
@PostConstruct
public void init(){
list = createAndFillItSomehow();
}
< ui:repeat value =#{bean.list}varStatus =loop>
< h:inputText value =#{bean.list [loop.index]}/>
< / ui:repeat>
使用 / code>(仅当您的环境支持EL 2.2或JBoss EL ):
private Map< String,String>地图; // + getter(不需要设置器)
@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。让我们假设一个名为 Par的$ / code>的属性
id
和值的Javabean类
其中映射到具有列 id
和值$的数据库中的
par
表c $ c>:
私人列表< Par>收杆; // + getter(不需要setter)
@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:
将其打开。
I would like to know if it possible to push a value from inside a to a map, a set or a list?
I would like to pass the value of the inputtext to a set.
Code:
<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>
Regards Markus
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.
With a 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>
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>
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.
这篇关于从< ui:repeat>内推出一个值在地图,设置或列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!