繁体   English   中英

为什么JSF找不到我的验证方法?

[英]Why does JSF not find my validation method?

我有这个simpe复合组件:

    <!-- INTERFACE -->
<cc:interface>
    <cc:attribute name="username" required="true" type="java.lang.String"/>
    <cc:attribute name="password" required="true" type="java.lang.String"/>
    <cc:editableValueHolder name="input" targets="username password"/>
    <cc:attribute name="validator" method-signature=
                  "void Action(javax.faces.context.FacesContext, 
                  javax.faces.component.UIComponent,Object)"
                  required="true"/>
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation>
    <h:panelGrid columns="3" styleClass="components" cellpadding="5px">
        <h:outputText value="#{msg['login.username']}"/>
        <h:inputText id="username" value="#{cc.attrs.username}" required="true"/>
        <h:message styleClass="error" for="username"/>
        <h:outputText value="#{msg['login.password']}"/>
        <h:inputSecret id="password" value="#{cc.attrs.password}" 
                       validator="#{cc.attrs.validator}" required="true"/>
        <h:message styleClass="error" for="password"/>
        <h:commandButton value="#{msg['login.confirm']}"/>
    </h:panelGrid>
</cc:implementation>

我以这种方式使用它(当然,所有这些都在ah:form标记内):

<imp:loginComponent username="#{databaseManager.username}" 
                            password="#{databaseManager.password}"
                            validator="#{databaseManager.validator}" >
        </imp:loginComponent>

在这里您可以看到我的验证方法:

 public void validator(FacesContext context, UIComponent component, Object value)
        throws ValidatorException {
    // ziskani username a password komponent
    UIInput passwordComponent = (UIInput) component;
    UIInput usernameComponent = ((UIInput) component.findComponent("username"));
    // az do teto chvile byl vstup validni?
    if (usernameComponent.isValid() && passwordComponent.isValid()) {
        // validace proti DB
        String username = usernameComponent.getValue().toString();
        String password = value.toString();
        if (!userRecordFacade.authorizedAcces(username, password)) {
            System.out.println("blbe");
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid", null);
            throw new ValidatorException(message);
        }
    }
}

一切正常,直到我通过ValidatorException。 没有例外,但在h:message中通过密码输入出现了一些奇怪的消息:/login.xhtml @ 16,75validator =“#{databaseManager.validator}”:类'com.dusek.DatabaseManager'没有属性'验证器'。

这怎么可能? 如果该方法未引发ValidatorException,则很好。 但这是非常糟糕的行为,我的意思是:-)。

你能告诉我一些建议吗? 谢谢。

我认为这是10000 ....复合组件的错误之一。 我认为在实现getter getValidator时可以解决。 它不会被使用,但是由于某些原因JSF想要它。

此外,为什么要一个动态的可重用登录组件? 您的应用程序有多少种不同的登录名? 我认为您根本不应该在这里使用复合组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM