0

Lately, I have been getting weird error's that mean one thing, but I'm experiencing another. Typically when this error occurs, it means that my Bean is not properly named, and therefore I am trying to reach a Bean that doesn't exist. An example can be found here: JSF Target unreachable identifier resolved to null.

In this case, I'm using CDI:

package account;

import general.Env;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;

import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

@ManagedBean(name="account")
@SessionScoped
public class Account implements Serializable{

String username;
String password;
String ouName;
String error = "";
Logger log = LogManager.getLogger("QCAuth");

public String getOuName() {
    return ouName;
}
public void setOuName(String ouName) {
    this.ouName = ouName;
}
public String getError() {
    return error;
}
public void setError(String error) {
    this.error = error;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}

My html that is throwing the error:

        <h:form id="form" method="post" onsubmit="return fullCheck()">

            <div id="userdiv" class="form-inline">
                <label for="username" class="control-label" style="color: #2E8AE6;margin-right:  
50px">Username: </label>
                <h:inputText class="form-control" id="user" style="margin-right: 125px" value="#
{account.username}"/>
            </div>

            <div class="form-inline">   
            &nbsp;
            </div>
            <div id="passdiv"  class="form-inline">
                <label for="password" class="control-label" style="color: #2E8AE6;margin-right: 
50px">Password: </label>
                <h:inputText class="form-control" id="pass" style="margin-right: 123px" value="#
{account.password}"/>
            </div>
            &nbsp;
            <div  class="form-inline">
                <h:commandButton styleClass="btn btn-primary" style="background-image:linear-
gradient(to bottom, #2E8AE6 0%,  #174470 100%);
                color:#000000" id="submit" value="Submit" action="#{account.login}"/>
            </div>  
        </h:form>

Stack trace:

WARNING: /index.xhtml @75,107 value="#{account.username}": Target Unreachable, identifier   
'account' resolved to null
javax.el.PropertyNotFoundException: /index.xhtml @75,107 value="#{account.username}": Target   
Unreachable, identifier 'account' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue
(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:67)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'account' resolved    
to null
at org.apache.el.parser.AstValue.getTarget(AstValue.java:97)
at org.apache.el.parser.AstValue.getType(AstValue.java:81)
at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:171)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)

I have my beans.xml (which is empty) in my WEB-INF folder. When trying to fill out a value or action of the jsf components, Eclipse provides "account" as a possible Bean, and I am able to pull the getters, setters, and methods of the Bean through default proposals. Essentially, Eclipse is telling me the bean is properly defined. Any possible cause of this error?

Edit: for whatever reason as well, when inspecting my web page before form submission occurs, my javascript has errors in it as well. I double checked and everything looks fine. Not sure if this would help

Edit 2: It turns out all my identifiers are appearing as null. Just tried my env bean and got the following stack trace:

javax.servlet.ServletException: javax.el.PropertyNotFoundException: /index.xhtml @102,259  
action="#{env.devMode}": Target Unreachable, identifier 'env' resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:67)

root cause

javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /index.xhtml @102,259    
action="#{env.devMode}": Target Unreachable, identifier 'env' resolved to null
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAd
apter.java:94)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:67)
root cause

javax.el.PropertyNotFoundException: /index.xhtml @102,259 action="#{env.devMode}": Target    
Unreachable, identifier 'env' resolved to null
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAd    apter.java:87)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:67)

Class:

package general;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Named;

@ManagedBean(name="env")
@ViewScoped
public class Env {

public static boolean prod = true;
public static String[] ouValues;
static int i = 0;

public static void initialize() 
{
    getConfigProperties config = new getConfigProperties();
    Properties prop = config.getConfig();

    String temp = prop.getProperty("ouValues");
    ArrayList<String> tempProdArr= new ArrayList<String>(Arrays.asList(temp.split("\\s*,\\s*")));
    ouValues=tempProdArr.toArray(new String[tempProdArr.size()]);
}

public static String[] getOuValues() {
    return ouValues;
}

public static void setOuValues(String[] ouValues) {
    Env.ouValues = ouValues;
}

public static boolean isProd()
{
    if (i == 0) {
        initialize();
        i = 1;
    }

    return prod;
}

public String devMode() {
    prod = false;
    return "index.xhtml";
}   

public void prodMode() {
    prod = true;
}
}

So basically, I have multiple beans that are being confused for being null identifiers when they are actually properly defined. Could my install of eclipse be causing this? Or maybe a tomcat related issue such as not properly loading my managed beans? I really have no clue where to go from here.

Community
  • 1
  • 1
antihero989
  • 469
  • 9
  • 29
  • As usual, what package is SessionScoped from? And what is fullCheck(), it seems to be a non-standard way of doing validation? – Jaqen H'ghar Aug 30 '14 at 10:57
  • Please include the full stack trace and your import statements. – John Ament Aug 30 '14 at 19:29
  • @JaqenH'ghar fullcheck() is just a validation method contained in a javascript file. The package is javax.faces.bean. – antihero989 Sep 02 '14 at 14:21
  • I have been struggling with this issue for two days now. It makes no sense. What seems to be working is to strip the class and xhtml page of everything then slowly add everything back, line by line. – nettie May 12 '21 at 20:16

1 Answers1

0

A failure to Define class org.apache.directory.ldap.client.api.LdapConnection was causing my Account class to not load. As a result, Tomcat was unable to find the class. After including this jar in my WEB-INF/lib folder, these errors went away.

antihero989
  • 469
  • 9
  • 29