Omnifaces ValidateEqual不执行验证

时间:2012-11-13 08:58:53

标签: jsf-2 omnifaces

我正在尝试使用Omnifaces验证器,尤其是validateEqual,因此我创建了一个测试页面。

<p:messages autoUpdate="true" showDetail="false" />
<h:form id="registerForm" prependId="false">
    <p:panelGrid columns="2" styleClass="register-grid">

        <h:outputLabel for="password" value="Password *" />
        <p:inputText id="password" value="" label="Password"
            requiredMessage="Password is required" size="30">
            <f:validateRequired />
        </p:inputText>

        <h:outputLabel for="confirmPassword" value="Confirm Password *"
            requiredMessage="Confirm Password is required" />
        <p:inputText id="confirmPassword" value="" label="Confirm Password" requiredMessage="Confirm password is required"
            size="30">
            <f:validateRequired />
        </p:inputText>

        <o:validateEqual components="password confirmPassword" message="Passwords are not equal"/>

        <f:facet name="footer">
            <p:commandButton value="Register" action="/pages/public/login"/>
            <p:commandButton value="Cancel" immediate="true" action="/pages/public/login"/>
        </f:facet>
    </p:panelGrid>
</h:form>

不确定,但没有任何事情发生,我从firebug下面看到错误。

<partial-response>
    <error>
        <error-name>class javax.faces.component.UpdateModelException</error-name>
        <error-message>/pages/public/register.xhtml @26,57 value="": Illegal Syntax for Set Operation</error-message>
    </error>
    <changes>
        <extension ln="primefaces" type="args">{"validationFailed":true}</extension>
    </changes>
</partial-response>

可能是什么原因?

1 个答案:

答案 0 :(得分:1)

/pages/public/register.xhtml @26,57 value="": Illegal Syntax for Set Operation

这基本上告诉我们不可能对空值表达式执行“set”操作(setter方法调用)。

完全删除value属性(至少从“confirm”字段中删除),或指定有效的值表达式,例如value="#{bean.password}"(至少对于第一个字段)。所以,基本上:

<p:inputText id="password" value="#{bean.password}" label="Password"
    requiredMessage="Password is required" size="30" required="true" />
<p:inputText id="confirmPassword" label="Confirm Password" 
    requiredMessage="Confirm password is required" size="30" required="true" />
<o:validateEqual components="password confirmPassword" 
    message="Passwords are not equal" />

这与使用<o:validateEqual>无关。不使用它时你会遇到完全相同的问题。但是,您可能希望使用OmniFaces FullAjaxExceptionHandler以便在ajax请求期间获得异常的真实错误页面,而不是完全缺乏视觉反馈。