Validator创建多条消息 - 不必要的“断言失败”消息

时间:2014-02-19 21:21:17

标签: jsf bean-validation

我有一个JSF验证器,它检查多个字段中的值(保存之前):

    <h:panelGrid columns="1" width="100%">
        <a:outputPanel ajaxRendered="true">
            <h:message for="#{bookDtlView.detailBean.editFormId}" 
                    styleClass="message" 
                    errorClass="errormsg" 
                    infoClass="infomsg" 
                    warnClass="warnmsg"/>
        </a:outputPanel>
    </h:panelGrid>

...

@AssertTrue
public boolean validateBean() {
    boolean valid = true;
    try {
        BookDtlView dtlv = (BookDtlView) getComponentInstance(BookDtlView.class);
        BookDtl dtl = dtlv.getDetailBean();

        Book book = dtl.getInstance();

        if (book.hasEnumerationStyledCode() && (book.getCode() != null)) {
            if (!topic.getCode().matches("^[A-Z][A-Z0-9_]*$")) {
                valid = false;
                getStatusMessages().add(Severity.ERROR, "Codes must begin with a capital letter and contain only capital letters, numbers, and underscores.");
            }
        }

        if (valid) {
            if (dtl.isDuplicate()) {
                valid = false;
                getStatusMessages().add(Severity.ERROR, "The selected code value is already in use.");
            }
        }


    } catch (Exception e) {
        valid = false;
        error(e);
        getStatusMessages().add(Severity.ERROR, "UNEXPECTED ERROR. Please navigate away from this page and report the problem.");
    }

    return valid;
}

当用户错误输入代码时,错误显示正确“代码必须以大写字母开头,并且只包含大写字母,数字和下划线。”但是控制台上也会显示错误:

信息:警告:FacesMessage已入队,但可能尚未显示。 sourceId = cteForm:j_id14 [severity =(ERROR 2),summary =(断言失败),detail =(断言失败)]

当我将JSF代码<h:message>切换到<h:messages>时,控制台内容消失了,但是Assertion Failed消息被添加到显示的错误列表中。

如何消除消息中的断言失败?

0 个答案:

没有答案
相关问题