最近,我得到了奇怪的错误,这意味着一件事,但我经历了另一件事。通常,当发生此错误时,这意味着我的Bean没有正确命名,因此我试图找到一个不存在的Bean。可以在此处找到一个示例:JSF Target unreachable identifier resolved to null。
在这种情况下,我使用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">
</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>
<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提供了&#34; account&#34;作为一个可能的Bean,我能够通过默认提议拉出Bean的getter,setter和方法。从本质上讲,Eclipse告诉我bean已正确定义。导致此错误的任何可能原因?
编辑:无论出于何种原因,在表单提交之前检查我的网页时,我的javascript也有错误。我仔细检查,一切都很好。不确定这是否有帮助
编辑2:事实证明我的所有标识符都显示为空。刚尝试了我的env bean并获得了以下堆栈跟踪:
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;
}
}
基本上,我有多个bean在实际正确定义时被混淆为空标识符。我可以安装eclipse吗?或者也许是与tomcat相关的问题,例如没有正确加载我的托管bean?我真的不知道从哪里开始。
答案 0 :(得分:0)
未定义类org.apache.directory.ldap.client.api.LdapConnection导致我的Account类无法加载。结果,Tomcat无法找到该课程。在我的WEB-INF / lib文件夹中包含这个jar之后,这些错误就消失了。