0

What I am trying to do is have a user click a button on a JSF webpage. Clicking the button on the webpage will trigger a method in a managed bean. This manage Bean should then call a EJB which runs asynchronously (method is RunManager getRoutesOnRun(int runID)., The issue I am getting is that after I have annotated the various parts of code I am getting an error message when the user clicks on the button within the webpage - "runRoutesBean" does not exist.

The webpage command button

The code for the command button is

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

Managed 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);
    }

}

The 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

    }

The Stack trace (partial)

Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'runRoutesBean' resolved to null

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

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

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

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

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

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Start with a simple piece of code. There is way too much in here that is not related to the issue. And there should be no need to configure JNDI lookups in your code like this in a Java-EE server... Using `@EJB` annotations should work fine and switching to `@Named` (with the corresponding `@SessionScoped`) is a good idea too. – Kukeltje Jul 24 '18 at 08:40
  • Making those changes seems to have cleared up many of the issues. The issue I am facing now is that when I click the run button . It is giving the following error /runAlgorithm.xhtml @51,100 value="#{runRoutesBean.runID}": Target Unreachable, identifier 'runRoutesBean' resolved to null. I am guessing this is because it is now an EJB bean but reading various internet posts it looks like the references remain the same. Any ideas? – Richard Faint Jul 24 '18 at 12:30
  • Sorry, in a CDI `@Named` managed bean you should use `@Inject` to get the ejb and not `@EJB` https://stackoverflow.com/questions/5060314/inject-a-stateless-ejb-with-inject-into-cdi-weld-managedbean-jsf-1-2-ejb-appli – Kukeltje Jul 24 '18 at 13:02
  • Changed it to @Inject but I am still getting the same issue /runAlgorithm.xhtml 51,100 value="#{runRoutesBean.runID}": Target Unreachable, identifier 'runRoutesBean' resolved to null – Richard Faint Jul 24 '18 at 14:32
  • is runRoutesBean an ejb or cdi managed bean? And please clean up your code in the post. Try making it a [mcve] so it becomes more readable. – Kukeltje Jul 24 '18 at 14:42
  • I am attempting to make it a managed Bean calling a EJB . I have edited the original post to try and make it easier to understand. Can you have another look? Thanks for the help . – Richard Faint Jul 25 '18 at 07:26
  • Make it an [mcve], not only remove things, and not other parts, imports, whitespace etc... And Like stated, _"@Named managed bean you should use @Inject to get the ejb and not @EJB"_ and your `@RequestScoped` annotation is wrong for a CDI managed bean (it is for JSF `@ManageBean`)... Change that too. – Kukeltje Jul 25 '18 at 07:57

0 Answers0