我有这个简单的复合组件:
<!-- 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,75 validator="#{databaseManager.validator}": The class 'com.dusek.DatabaseManager' does not have the property '验证器'。
这怎么可能?如果该方法没有抛出 ValidatorException,那很好。但这是非常糟糕的行为,我的意思是:-)。
你能告诉我一些建议吗?谢谢。