我正在编写一个JSF页面,用户可以在其中更改密码。我基于David Geary和Cay S. Horstmann撰写的JavaServer Faces(第3版)一书中的代码示例来构建我的解决方案。这里是我的代码:未找到验证方法
部分 AccountBean.java<h:inputText id="oldPassword" required="true"
validator="#{accountBean.validateOldPassword}">
<f:ajax event="blur" render="oldPasswordError" />
</h:inputText>
<h:message for="oldPassword" id="oldPasswordError" style="color: red" />
:
@Named("accountBean")
@SessionScoped
public class AccountBean implements Serializable {
private String login;
private String password;
(...)
public void validateOldPassword(FacesContext context, UIComponent component, Object value) {
if (!(((String)value).equals(password)))
throw new ValidatorException(new FacesMessage("Invalid password"));
}
}
现在,当我部署到这个JBoss AS中7.0.2,并尝试使用我得到这样的错误呈现近老密码字段:
/changePassword.xhtml @28,54 validator="#{accountBean.validateOldPassword}": Method not found: [email protected]ateOldPassword(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
它声称该方法无法找到,为什么呢? 这几乎是从书中复制/粘贴,仍然无法正常工作。 我不知道在哪里可以找到一个bug。你可以帮帮我吗?
看起来不错。当然,你确实重建/重新部署了WAR并最终重新启动了服务器(或者服务器本身正确支持auto-hotdeploy)?没有该方法的旧类可能仍然在服务器的工作文件夹中。如果不能解决这个问题,那么为了消除可能的CDI噪声,请改用`javax.faces.bean`包中的`@ManagedBean @ SessionScoped`(或更好的方法``ViewScoped`)。 – BalusC 2011-12-14 16:22:57