在同一托管 Bean 属性中保存多个字段
从此处开始,我遇到以下问题:
我正在生成随机数量的表单字段(不是那么随机,但用户可以随时更改其数量),并且我想将所有这些信息保存在托管 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到转换错误,因为您尝试将提交的
String
值设置为List
属性,而该属性不存在标准转换器,而且您也没有该属性t 声明任何转换器。毕竟,你不应该需要任何人。这个语法根本不正确。您需要将
String
值绑定到String
属性。您需要通过索引来引用列表。我也不确定为什么你需要两个列表。tipCounter
似乎完全没有必要。这是重写:
您可能还想在循环内添加
。You got a conversion error because you're attempting to set a submitted
String
value as aList<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 aString
property. You need to reference the list by the index instead. I'm also not sure why you need 2 lists for this. ThetipCounter
seems totally unnecessary.Here's a rewrite:
You might want to add a
<h:message for="tip" />
inside the loop as well.