我如何绑定一个输入框的值要在支持Bean属性映射值使用向导时 [英] How do I bind a inputbox values to a map value in a backing bean property when using a wizard

查看:97
本文介绍了我如何绑定一个输入框的值要在支持Bean属性映射值使用向导时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Primefaces向导组件。在一个选项卡我以previous选项卡输入(用户类型)正在动态创建输入框。输入框文本标签从列表中的。我支持bean中,我有一个地图,其中包含输入标签的按键和输入框输入,值。

I am using the Primefaces wizard component. On one tab I am dynamically creating input boxes based on previous tabs input(user type). The inputbox text labels are derived from a list. In my backing bean, I have a map that contains input labels as keys and inputbox inputs as values.

点击下,我想在地图(值),以与用户的输入(相应于键)

Clicking on next, I would like the map(values) to be updated with the user input (corresponding to the key)

<c:forEach items="#{gdsiGeodataBean.actionCommand.fields}" var="reqs">
  <h:outputLabel for="#{reqs.name}" value="#{reqs.name}:* " />  
  <pou:inputText value="#{gdsiGeodataBean.actionCommand.values['reqs.name']}"  required="true" requiredMessage="Input is required."/> 
</c:forEach>

我支持bean:

My backing bean :

private List<RequiredParam> fields; // +getter (no setter required)
private Map<String, String> values; // +getter (no setter required)

public CommandAction(String actionName, String actionParams, String context) {
    this.actionName = actionName;
    this.actionParams = actionParams;
    this.contextName = context;

    //Set up parameters
    getRequiredParams();
    getOptionalParams();
    fields = getFields();
    values = new HashMap<String, String>();
}

基本上我想什么是与从TextInput箱用户输入更新的地图值。

Essentially what I would like is for the map values to be updated with user inputs from the textinput boxes.

推荐答案

您输入值绑定到地图的做法是不完全正确的。

Your approach to bind the input value to a map is not entirely correct.

<pou:inputText value="#{gdsiGeodataBean.actionCommand.values['reqs.name']}"  required="true" requiredMessage="Input is required."/> 

你指定的固定地图键,而不是基于当前迭代#{}请求数动态地图键。这样,所有提交值将在一个相同的固定地图键reqs.name,其中每一个覆盖对方结束了,所以你只获得最后的值场中的图

You're specifying a fixed map key instead of a dynamic map key based on the currently iterated #{reqs}. This way all submitted values will end up in one and same fixed map key "reqs.name", whereby each one overrides each other so that you only get the value of the last field in the map.

您需要删除这些singlequotes使它一个真正动态密钥。

You need to remove those singlequotes to make it a really dynamic key.

<pou:inputText value="#{gdsiGeodataBean.actionCommand.values[reqs.name]}"  required="true" requiredMessage="Input is required."/> 


无关以具体的问题,即使是,在你的问题这种方法可以使用​​时正常工作, c为C:的forEach&GT; 会在某些情况下会失败。例如。复合组件或迭代JSF组件内使用时。而使用&LT; UI:重复&GT; 来代替。另见JSF2 Facelets的 JSTL ...有道理?


Unrelated to the concrete question, even though this approach will work when used as-is in your question, the <c:forEach> will fail in certain circumstances. E.g. when used inside a composite component or an iterating JSF component. Rather use <ui:repeat> instead. See also JSTL in JSF2 Facelets... makes sense?

这篇关于我如何绑定一个输入框的值要在支持Bean属性映射值使用向导时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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