【发布时间】:2014-08-29 16:07:16
【问题描述】:
最近,我遇到了奇怪的错误,这意味着一件事,但我正在经历另一件事。通常,当发生此错误时,这意味着我的 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 提供“帐户”作为可能的 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?我真的不知道从这里去哪里。
【问题讨论】:
-
像往常一样,SessionScoped 来自哪个包?而fullCheck()是什么,它似乎是一种非标准的验证方式?
-
请包含完整的堆栈跟踪和您的导入语句。
-
@JaqenH'ghar fullcheck() 只是一个包含在 javascript 文件中的验证方法。包是 javax.faces.bean。
-
我已经为这个问题苦苦挣扎了两天了。这没有道理。似乎可行的是剥离所有内容的类和 xhtml 页面,然后逐行缓慢地添加所有内容。