当我运行登录jsf页面时,我收到以下错误。我认为我的托管 Bean 中的valider()
功能是问题所在,但我没有找到方法
在我的 ejb 中验证函数:
@Override
public Client authentificate(String login, String pwd) {
Client client=null;
Query query=entityManager.createQuery("select c from Client c where c.login=:l and c.pwd=:p");
query.setParameter("l", login).setParameter("p",pwd);
try {
client=(Client) query.getSingleResult();
} catch (Exception e) {
client=null;
}
return client;
}
托管豆:
@ManagedBean
@SessionScoped
public class LoginClientBean {
@EJB
GestionClientLocal local;
private String login;
private String pwd;
private boolean connected;
public static Client client;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
String message=null;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean isConnected() {
return connected;
}
public void setConnected(boolean connected) {
this.connected = connected;
}
public Client getClient() {
return client;
}
public String valider(){
String nav =null;
client=local.authentificate(login, pwd);
if (client != null){
nav="/pages/yes?faces-redirect=true";
}else {
nav="/pages/no?faces-redirect=true";
}
return nav;
}
public String deconnexion(){
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().clear();
return "/pages/login?faces-redirect=true";
}
}
JSF 页面:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>Flate Signup And Login Form with Flat Responsive template :: w3layouts</title>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<h:outputStylesheet library="css" name="style.css"></h:outputStylesheet>
<h:outputScript type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </h:outputScript>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="login" />
<p:inputText value="#{loginClientBean.login}" />
<h:outputText value="password" />
<p:password value="#{loginClientBean.pwd}" />
<p:commandButton value="login" action="#{loginClientBean.valider()}" ajax="false"/>
</h:panelGrid>
</h:form>
</h:body>
</html>
从操作方法中删除 ((
<p:commandButton value="login" action="#{loginClientBean.valider}" ajax="false"/>
为受管 Bean 命名(请注意,它应该在不指定名称的情况下工作(
@ManagedBean(name="loginClientBean ")
@SessionScoped
public class LoginClientBean {
.....
}
如果您使用的是 JSF 2.2,请将 jdk 替换为 1.7 及更高版本.最后在部署之前给出正确的构建
另请查看巴鲁 c 解决方案 https://stackoverflow.com/a/30128396/4036926