如何设置< h:inputText>的提交值在< ui:repeat>内部进入地图,集合或列表 [英] How to set submitted values of <h:inputText> inside <ui:repeat> into map, set or list

查看:148
本文介绍了如何设置< h:inputText>的提交值在< ui:repeat>内部进入地图,集合或列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以将<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,它是不可能的,因为它不允许按索引或键引用项目.但是,只需在输入值中指定列表索引和映射键,就可以使用ListMap.

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>


使用Map(仅当您的环境


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.假设具有属性idvalue的名为Par的Javabean类准确地映射到DB中具有列idvaluepar表:


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.

这篇关于如何设置&lt; h:inputText&gt;的提交值在&lt; ui:repeat&gt;内部进入地图,集合或列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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