JSF与EJB集成

JSF与EJB集成,jsf,jakarta-ee,ejb,session-bean,entity-bean,Jsf,Jakarta Ee,Ejb,Session Bean,Entity Bean,我试图为我的应用程序创建一个登录页面,但我在第一步就被卡住了。在我的bean中使用会话外观之前,我的表单工作正常,在添加会话外观之后,我获得了属性not found exception: 我的网页是: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/x

我试图为我的应用程序创建一个登录页面,但我在第一步就被卡住了。在我的bean中使用会话外观之前,我的表单工作正常,在添加会话外观之后,我获得了属性not found exception:

我的网页是:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <f:view contentType="text/html">
        <h:head>
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <title>PrimeFaces</title>
            </f:facet>
        </h:head>

        <h:body>
            <h:form>
            <p:panelGrid columns="2">
                <p:outputLabel value ="Username"/> <p:inputText id="userName" value="#{loginBean.user}"/> 
                <p:outputLabel value ="Password"/> <p:inputText id="password" value="#{loginBean.password}"/>
            </p:panelGrid>
                <p:commandButton value="Login" actionListener="#{loginBean.doLogin}"/>
            </h:form>
        </h:body>

    </f:view>
</html>
不工作的bean代码是:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import entities.Program;
import entities.ProgramFacade;
import entities.ProgramFacadeLocal;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Salman Ahmed Ansari
 */
@Named(value = "loginBean")
@SessionScoped
public class LoginBean implements Serializable {
    @EJB
    private ProgramFacade programFacade;

    /**
     * Creates a new instance of LoginBean
     */
    private String user;
    private String password;

    public String getUser() {
        return user;
    }

    public String getPassword() {
        return password;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void doLogin(ActionEvent listener){
        System.out.println(user);
        System.out.println(password);
    }

    public LoginBean() {

    }
}
什么触发了这个异常


提前感谢。

请通过捕获异常并将其打印为异常来记录异常的stacktrace。PrintStackTrace三个小提示;@Names的value属性是多余的。您使用的值已经是默认值。@SessionScoped不太可能是您试图解决的问题的最佳范围。当在多个选项卡中打开同一页时,您将遇到问题。很可能您希望在此处设置@viewscope。登录操作似乎是主要操作。按照惯例,最好使用直接操作,而不是actionListener。
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import entities.Program;
import entities.ProgramFacade;
import entities.ProgramFacadeLocal;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Salman Ahmed Ansari
 */
@Named(value = "loginBean")
@SessionScoped
public class LoginBean implements Serializable {
    @EJB
    private ProgramFacade programFacade;

    /**
     * Creates a new instance of LoginBean
     */
    private String user;
    private String password;

    public String getUser() {
        return user;
    }

    public String getPassword() {
        return password;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void doLogin(ActionEvent listener){
        System.out.println(user);
        System.out.println(password);
    }

    public LoginBean() {

    }
}