开发者

Validate richfaces:dataTable against no data

I would like to validate my richfaces:datatable component against empty. In other words I have <rich:dataTable value="#{bean.list}" ...> and list m开发者_如何学运维ust have at least one element. Is there some good sollution for this kind of validation.

Regards, A


You can't use a validator for this. It's for submitted request parameters only. If the sole purpose is to display some message when the list is empty, then just use the rendered attribute.

<rich:dataTable value="#{bean.list}" rendered="#{not empty bean.list}">
    ...
</rich:dataTable>
<h:outputText value="List is empty!" rendered="#{empty bean.list}" />

Update: the table seems to be part of a form. Best what you could do is to add a FacesMessage yourself in the bean's action method.

public String submit() {
    if (list.isEmpty()) {
        FacesContext.getCurrentInstance().addMessage(null, 
            new FacesMessage("Please add at least one item"));
        return null;
    }

    // ...
}

with a

<h:messages globalOnly="true" />

which shows only messages with a null client ID.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜