JSF 2.0:为什么我的 selectManyListbox 值无效
在我的 ManagedBean 中,我有以下属性:
@ManagedBean
@RequestScoped
public class MrBean {
...
private long[] IDs;
private List<Item> items;
...
}
在我的 .xhtml 文件中,我有以下选择多个框:
<h:selectManyListbox label="abc"
id="abc" size="5" value="#{MrBean.IDs}">
<f:selectItems value="#{MrBean.items}" var="i"
itemLabel="#{i.name}" itemValue="#{i.id}" />
</h:selectManyListbox>
<h:message styleClass="errorMsg" for="abc" />
我的项目的 id 是长数字。因此,我希望能得到一份选定的 ID 列表。但是,当我提交表单时,abc: Validation Error: Value is not valid
出现在列表框的消息部分中。
有人可以告诉我我在这里做错了什么吗?
此致, 詹姆斯·特兰
In my ManagedBean, I have the following property:
@ManagedBean
@RequestScoped
public class MrBean {
...
private long[] IDs;
private List<Item> items;
...
}
In my .xhtml file, I have the following select many box:
<h:selectManyListbox label="abc"
id="abc" size="5" value="#{MrBean.IDs}">
<f:selectItems value="#{MrBean.items}" var="i"
itemLabel="#{i.name}" itemValue="#{i.id}" />
</h:selectManyListbox>
<h:message styleClass="errorMsg" for="abc" />
The id of my items are long numbers. Hence, I expected that I would get a list of IDs chosen. However, when I submit the form, abc: Validation Error: Value is not valid
appears in the message part for my list box.
Can someone please tell what I have done wrong here?
Best regards,
James Tran
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在处理表单提交期间,如果所选项目与任何可用项目都不匹配,您将收到此验证错误。
由于您的 bean 属于请求范围,因此您需要确保在 bean 的(post)构造函数中创建与显示表单时完全相同的
List
。如果由于列表的内容取决于先前的操作而无法实现,那么您需要将 bean 放入视图范围中。You will get this validation error when the selected item(s) doesn't match any of the available items during processing the form submit.
As your bean is request scoped, you need to ensure that you create exactly the same
List<Item>
in bean's (post)constructor as it was when the form is been displayed. If that's not possible because the contents of the list depends on a previous action, then you need to put the bean in the view scope.