Target Unreachable,Identifier resolved null and defined defined Bean

问题描述:

最近我收到奇怪的错误,这意味着一件事,但我正在经历另一件事。通常当发生这种错误时,这意味着我的Bean没有正确命名,因此我试图访问一个不存在的Bean。一个例子可以在这里找到:JSF Target unreachable identifier resolved to nullTarget Unreachable,Identifier resolved null and defined defined Bean

在这种情况下,我使用CDI:

包帐户;

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

我的HTML是引发错误:

 <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> 

堆栈跟踪:

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) 

我有我在我的WEB-INF文件夹中的beans.xml(里面是空的)。当试图填写jsf组件的值或动作时,Eclipse提供了“account”作为可能的Bean,并且我能够通过默认提议来获取Bean的getter,setters和方法。本质上,Eclipse告诉我这个bean已被正确定义。这个错误的任何可能的原因?

编辑:无论出于什么原因,在表单提交前检查我的网页时,我的javascript也有错误。我加倍检查,一切都很好。不知道这是否会有所帮助

编辑2:事实证明,我所有的标识符都显示为空。只是想我的ENV豆,得到了下面的堆栈跟踪:

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) 

类:

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

所以基本上,我正在困惑的是,他们实际上是正确定义当空标识符多豆类。我的安装eclipse是否会造成这种情况?或者也许是一个tomcat相关的问题,比如没有正确加载我的托管bean?我真的不知道该从哪里出发。

+0

像往常一样,SessionScoped从哪个包?什么是fullCheck(),它似乎是一种非标准的验证方式? – 2014-08-30 10:57:47

+0

请包括完整的堆栈跟踪和您的导入语句。 – 2014-08-30 19:29:30

+0

@ JaqenH'ghar fullcheck()只是一个包含在JavaScript文件中的验证方法。该包是javax.faces.bean。 – antihero989 2014-09-02 14:21:46

无法定义类org.apache.directory.ldap.client.api.LdapConnection导致我的Account类无法加载。结果,Tomcat无法找到该课程。将这个jar包含在我的WEB-INF/lib文件夹中后,这些错误消失了。