在同一Managed Bean属性中保存多个字段 [英] Saving multiple fields in the same Managed Bean property

查看:49
本文介绍了在同一Managed Bean属性中保存多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处开始,我遇到以下问题:

Starting from here I have the following problem:

我正在生成随机数量的表单字段(不是随机的,但是用户可以随时更改其数量),并且我想将所有这些信息保存在Managed Bean ArrayList 中.属性.

I'm generating a random number of form fields (It's not that random, but the user can change in any moment their number) and I want to save all this information in a Managed Bean ArrayList property.

<ui:repeat var = "ctr" value = "#{controller.tipCounter}">
    <h:outputLabel for = "tip" value = "#{appMessage['form.tip']} ##{ctr} :" />
    <h:inputText id = "tip" value="#{controller.tipList}" maxlength="100" />
</ui:repeat>

在控制器中,我具有以下属性:

In the controller I have the following property:

private List<String>tipList;
//Get+Set

除了某些不良行为(映射此列表的所有表单字段均以 [] 作为其值)之外,还会引发以下警告:

Besides some undesired behaviour (all the form fields mapping this list have [] as their value) this warnings are thrown:

INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=fm-story:j_idt60:0:tip[severity=(ERROR 2), summary=(Conversion Error setting value '' for 'null Converter'.), detail=(Conversion Error setting value '' for 'null Converter'.)]
sourceId=fm-story:j_idt60:1:tip[severity=(ERROR 2), summary=(Conversion Error setting value '' for 'null Converter'.), detail=(Conversion Error setting value '' for 'null Converter'.)]

推荐答案

由于尝试将已提交的 String 值设置为 List< String> <,而导致转换错误/code>属性,该属性不存在标准转换器,并且尚未声明任何转换器.

You got a conversion error because you're attempting to set a submitted String value as a List<String> property, for which no standard converter exists and for which you haven't declared any converter.

毕竟,您不需要任何一个.此语法根本不正确.您需要将 String 值绑定到 String 属性.您需要通过索引来引用列表.我也不确定为什么要为此列出2个清单. tipCounter 似乎完全没有必要.

After all, you shouldn't need any one. This syntax is simply not correct. You need to bind a String value to a String property. You need to reference the list by the index instead. I'm also not sure why you need 2 lists for this. The tipCounter seems totally unnecessary.

这里是一个重写:

<ui:repeat value="#{controller.tipList}" var="tip" varStatus="loop">
    <h:outputLabel for="tip" value="#{appMessage['form.tip']} ##{loop.count} :" />
    <h:inputText id="tip" value="#{controller.tipList[loop.index]}" maxlength="100" />
</ui:repeat>

您可能还想在循环内添加< h:message for ="tip"/> .

You might want to add a <h:message for="tip" /> inside the loop as well.

这篇关于在同一Managed Bean属性中保存多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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