简体   繁体   中英

Why does JSF not find my validation method?

I have got this simpe composite component:

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

I am using it this way (all inside ah:form tag of course):

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

Here you can see my validation method:

 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);
        }
    }
}

Everything works fine until I thwor the ValidatorException. There is no exception but some strange message in h:message by password input: /login.xhtml @16,75 validator="#{databaseManager.validator}": The class 'com.dusek.DatabaseManager' does not have the property 'validator'.

How is it possible? If the method does not throw the ValidatorException, it is good. But this is very bad behaviour, I mean :-).

Could you tell me some advice? Thanks.

I think this is one of the 10000.... bugs of composite components. I think it is solved when you implement a getter getValidator. It won't be used, but for some reason JSF wants it.

Furthermore why do want a reusable login component which is so dynamic? How many different variations of logins does your application have? I think you should not use a composite component here at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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