JSF页面 - javax.el.PropertyNotFoundException:目标不可达,标识符 '索引' 解析为空
我想要实现在此基础上tutorial与JSF 2.2JSF页面 - javax.el.PropertyNotFoundException:目标不可达,标识符 '索引' 解析为空
faces-config.xml中
简单的JSF页面<?xml version="1.0"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>es</supported-locale>
</locale-config>
<resource-bundle>
<base-name>com.web.common.internationalization.text</base-name>
<var>text</var>
</resource-bundle>
</application>
</faces-config>
的index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="#{index.language}"
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view locale="#{index.locale}">
<h:head>
</h:head>
<h:body>
<h:form>
<h:selectOneMenu value="#{index.language}" onchange="submit()">
<f:selectItem itemValue="en" itemLabel="English" />
<f:selectItem itemValue="es" itemLabel="Spanish" />
</h:selectOneMenu>
</h:form>
<address class="top-address">
<span><h:outputText value="#{text['customer.support']}" /></span>
</address>
</h:body>
</f:view>
</html>
CDI豆
import java.io.Serializable;
import java.util.Locale;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
@Named
@SessionScoped
public class Index implements Serializable
{
private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
public Locale getLocale()
{
return locale;
}
public String getLanguage()
{
return locale.getLanguage();
}
public void setLanguage(String language)
{
this.locale = new Locale(language);
}
}
我在这里添加文字的Java类从教程和属性文件。
但由于某些原因,当我打开网页,我得到错误代码500。你有地方我错了什么想法?
错误堆栈:
javax.el.PropertyNotFoundException: /index.xhtml @15,80 value="#{index.language}": Target Unreachable, identifier 'index' 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 com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:201)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:318)
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.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:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'index' resolved to null
你认错进口 - 的@SessionScoped
是从脸包,它应该是从javax.enterprise.context
包一个。
或者您可以将@Named
切换为@javax.faces.bean.ManagedBean
,然后@SessionScoped将匹配(但它不再是CDI bean)。
引用'重复'是一个选项;-):http://stackoverflow.com/questions/11986847/java-ee-6-javax-annotation-managedbean-vs-javax-inject -named-vs-javax-faces – Kukeltje
现在我在这一行获得NPE'private Locale locale = FacesContext.getCurrentInstance()。getViewRoot()。getLocale();' –
@Kukeltje:如果每个人都这样做了,那么就不会有StackOverflow我们知道它:-) – fdreger
您应该发布与错误相关的服务器日志500 –
发布更新 –
@perissf:关于错误是,关于'解决方案'不是。 – Kukeltje