Reputation: 2205
<h:form id="form">
Username: <br/>
<h:inputText id="username" value="#{home.username}" required="true" >
<f:validator validatorId="loginValidator"></f:validator>
<f:attribute name="passwordComponent" value="#{passwordComponent}" ></f:attribute>
</h:inputText>
<br/>
Password: <br />
<h:inputText id="password" bindig="#{passwordComponent}" value="#{home.password}" required="true"></h:inputText>
<br/>
<h:commandButton value="login" id="login" action="#{home.login}"></h:commandButton>
</h:form>
public class LoginValidator implements Validator {
@Override
public void validate(FacesContext context, UIComponent component, Object value)
throws ValidatorException {
String username = (String)value;
UIInput passwordInput = (UIInput)component.getAttributes().get("passwordComponent");
String password = (String) passwordInput.getValue();
if(username!="aa" || password!="aa"){
passwordInput.setValid(false);
throw new ValidatorException(new FacesMessage("Wrong username or password!"));
}
}
}
at this line I get NuulPointerException:
String password = (String) passwordInput.getValue();
Why?
Upvotes: 1
Views: 552
Reputation: 7395
Spellings of the word "binding" is incorrect in following line.
<h:inputText id="password" bindig="#{passwordComponent}"...
change bindig to binding.
Upvotes: 2