在RichFaces中,当使用电子邮件验证时,我得到NullPointer异常?
BeanClass代码是:
在RichFaces中,当使用电子邮件验证时,我得到NullPointer异常?
public void validEmail(FacesContext context, UIComponent component,
Object value) throws Exception
{
//Set the email pattern string
Pattern p = Pattern.compile("[email protected]+\\.[a-z]+");
//Match the given string with the pattern
Matcher m = p.matcher(email);
//check whether match is found
boolean matchFound = m.matches();
if (matchFound)
System.out.println("Valid Email Id.");
else
System.out.println("Invalid Email Id.");
}
.xhtml代码是:
<h:inputText title="Enter Email Address" value="#{registerBean.email}" id="eMail" required="true" validator="#{registerBean.validEmail}">
<rich:ajaxValidator event="oninputblur"/>
</h:inputText>
<rich:message for="eMail"/>
例外是:
/Register.xhtml @68,138 validator="#{registerBean.validEmail}": java.lang.NullPointerException
我该如何纠正这一点!
您需要验证value
这是一直在通过作为方法的参数,而不是局部变量email
,只是因为它尚未设置(它已先验证!)。它只会在验证阶段后设置,即更新模型值阶段。
因此,通过
Matcher m = p.matcher(value);
遗憾的点空,我没有得到你。 – 2010-10-15 12:25:28
我怎样才能从.xhtml页面的值到我的bean? – 2010-10-15 12:26:05
帮帮我!请 – 2010-10-15 12:26:24
检查更换
为什么registerBean是在执行 – 2010-10-15 11:39:54