开发者

JSF 2.0: why my selectManyListbox 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 开发者_JAVA技巧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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜