我想尝试一个简单的JSF 2教程示例.
我在Eclipse中使用动态Web项目并发布到Glassfish 3服务器(运行 - >在服务器上运行).第一个index.xhtml页面正确加载,但是当我必须访问托管bean时,会显示以下错误:
/index.xhtml @14,48 value="#{helloBean.name}": Target Unreachable, identifier 'helloBean' resolved to null
Run Code Online (Sandbox Code Playgroud)
我已经看过关于这个主题的各种其他讨论,但是这些解决方案对我来说似乎永远不会起作用(例如,添加beans.xml,根据命名约定给托管bean命名等).
任何帮助,将不胜感激.
这是我目前正在使用的代码:
的index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body>
<h3>JSF 2.0 Hello World Example - hello.xhtml</h3>
<h:form>
<h:inputText value="#{helloBean.name}"></h:inputText>
<h:commandButton value="Welcome Me" action="response"></h:commandButton>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
response.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head> …Run Code Online (Sandbox Code Playgroud) 我试图让JSF设置使用具有html扩展名的文件.
如果我使用.xhtml模式(<url-pattern>*.xhtml</url-pattern>)并使用xhtml扩展名命名我的文件,那么页面会正确加载并进行解析.
但是,如果我将其更改为<url-pattern>*.html</url-pattern>并使用.html扩展名命名文件,则会出现500错误:
The server encountered an internal error () that prevented it from fulfilling this request.
Exception: java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
服务器日志:
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at com.sun.faces.context.flash.ELFlash.getPhaseMapForReading(ELFlash.java:748)
at com.sun.faces.context.flash.ELFlash.isEmpty(ELFlash.java:466)
at com.sun.faces.facelets.util.DevTools.writeVariables(DevTools.java:318)
at com.sun.faces.facelets.util.DevTools.writeVariables(DevTools.java:208)
at com.sun.faces.facelets.util.DevTools.debugHtml(DevTools.java:123)
at com.sun.faces.renderkit.RenderKitUtils.renderHtmlErrorPage(RenderKitUtils.java:1139)
at com.sun.faces.context.ExceptionHandlerImpl.throwIt(ExceptionHandlerImpl.java:249)
at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:136)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) …Run Code Online (Sandbox Code Playgroud)