难以理解JNDI查找的将托管Bean转换为EJB

时间:2018-07-24 07:32:52

标签: jsf ejb cdi

我要做的是让用户单击JSF网页上的按钮。单击网页上的按钮将触发托管bean中的方法。然后,此管理Bean应该调用一个异步运行的EJB(方法是RunManager getRoutesOnRun(int runID)。),我遇到的问题是,在注释了代码的各个部分之后,当用户单击“代码”时,我收到了一条错误消息。网页内的按钮-“ runRoutesBean”不存在。

网页命令按钮

命令按钮的代码为

   <h:commandButton value="Run!" action="#{runRoutesBean.setrunAlgorithm(runRoutesBean)}"> 
             </h:commandButton>

受管Bean

package Beans;

import AlgorithmAndLogic.Route;
import AlgorithmAndLogic.RunManager;
import DataBaseConnections.RunRouteDataBaseConnectivity;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.ejb.SessionBean;
import javax.ejb.Stateless;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


@Named(value = "runRoutesBean")
@RequestScoped
public class RunRoutesBean {

    @EJB
    private RunManager runManager;

    private int runRoutesID;
    private int runID;
    private int routeID;
    private String runDescription; 
    private String routeDescription; 
    private int locationsOnRoute;
    private double originalDistance;
    private double crossOverRate; 
    private double mutationRate; 
    private String survivalStrategy; 
    private int terminationCycle;

          public void setrunAlgorithm(RunRoutesBean newRunRoutesObj) throws SQLException, IOException, NamingException {

            runID = newRunRoutesObj.runID; //gets the runID from the RunRouteObj

          runManager.getRoutesOnRun(runID);
    }

}

EJB

 package AlgorithmAndLogic;

 import javax.ejb.*;



 @Stateless public class RunManager{

    // Holds our routes
    private ArrayList run = new ArrayList<>();

    @Asynchronous
    public void getRoutesOnRun(int runID) throws SQLException, IOException{

        Does some work

    }

堆栈跟踪(部分)

  

原因:javax.el.PropertyNotFoundException:无法到达目标,标识符“ runRoutesBean”解析为null

     

com.sun.el.parser.AstValue.getTarget(AstValue.java:174)

     

在com.sun.el.parser.AstValue.getType(AstValue.java:86)

     在

  com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)

     在

  org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)

     在

  com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98

0 个答案:

没有答案