【问题标题】:JSF multiple field validation NULLPointerExceptionJSF 多字段验证 NULLPointerException
【发布时间】:2012-12-23 11:52:55
【问题描述】:
<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!"));
    }
}

}

在这一行我得到 NuulPointerException:

字符串密码 = (String) passwordInput.getValue();

为什么?

【问题讨论】:

    标签: jsf jsf-2 validation


    【解决方案1】:

    下一行中“binding”的拼写不正确。

    <h:inputText id="password"  bindig="#{passwordComponent}"...
    

    bindig 更改为 binding

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 2011-08-14
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多