1

我正在尝试 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>

不确定,但什么都没有发生,我从下面的错误中看到了萤火虫。

<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>

可能是什么原因?

4

1 回答 1

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

这基本上说明不可能对空值表达式执行“设置”操作(setter 方法调用)。

要么value完全删除该属性(至少从“确认”字段中删除),要么指定一个有效的值表达式,例如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>。不使用它时,您会遇到完全相同的问题。但是,您可能希望使用 OmniFacesFullAjaxExceptionHandler在 ajax 请求期间获得有关异常的真正错误页面,而不是完全缺乏视觉反馈。

于 2012-11-13T12:33:39.420 回答