0

运行登录 jsf 页面时出现以下错误。我认为我valider()在托管 Bean 中的功能是问题,但我没有找到方法

在我的 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>
4

1 回答 1

0

从动作方法中删除()

    <p:commandButton value="login" action="#{loginClientBean.valider}" ajax="false"/>

为您的托管 bean 命名(注意它应该在不指定名称的情况下也可以工作)

 @ManagedBean(name="loginClientBean ")
 @SessionScoped
 public class LoginClientBean {
   .....
  }

如果您使用的是 JSF 2.2,请将 jdk 替换为 1.7 及更高版本。最后在部署之前进行适当的构建

还可以查看 balu c 解决方案https://stackoverflow.com/a/30128396/4036926

于 2017-02-14T04:25:14.430 回答