在同一托管 Bean 属性中保存多个字段

发布于 2025-01-07 22:12:30 字数 1152 浏览 1 评论 0原文

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

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

<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>

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

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

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

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'.)]

Starting from here I have the following problem:

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'.)]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱暴击 2025-01-14 22:12:30

您遇到转换错误,因为您尝试将提交的 String 值设置为 List 属性,而该属性不存在标准转换器,而且您也没有该属性t 声明任何转换器。

毕竟,你不应该需要任何人。这个语法根本不正确。您需要将 String 值绑定到 String 属性。您需要通过索引来引用列表。我也不确定为什么你需要两个列表。 tipCounter 似乎完全没有必要。

这是重写:

<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>

您可能还想在循环内添加

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.

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.

Here's a rewrite:

<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>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文