我正在处理一个项目的问题我正在使用带有Facelets视图技术的Spring MVC。在我的主模板中,我目前正在使用菜单,每当我点击该菜单中的链接时,我的意图是包括当前的另一页。我点了这个链接How to ajax-refresh dynamic include content by navigation menu? (JSF SPA),但它没有解决我的问题。在示例中,我默认包含一个页面,它最初加载,一切似乎都没问题但是当我点击其中一个链接时,我得到一个空指针异常。
我想说我读过许多用户@BalusC回答的帖子,但我仍然没有找到解决方案。现在我被困在项目的这一部分,我觉得几乎不可能继续。
菜单xhtml文件如下:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:panelGroup layout="block" id="menu-outer">
<h:panelGroup layout="block" class="table">
<h:form>
<f:ajax render=":content">
<ul id="mainNav">
<li>
<h:commandLink id="toRegister" value= "Register page" action="#{bean.setPage('registerPage')}" />
</li>
<li>
<h:commandLink id="toDepartment" value= "Departments" action="#{bean.setPage('departmentPage')}"/>
</li>
<li>
<h:commandLink id="toHealthcarePlan" value= "Healthcare plans" action="#{bean.setPage('healthPage')}" />
</li>
<li>
<h:commandLink id="toContacts" value= "Contacts" action="#{bean.setPage('contactsPage')}" />
</li>
</ul>
</f:ajax>
</h:form>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup id="content" layout="block">
<ui:include src="/WEB-INF/view/#{bean.page}.xhtml" />
</h:panelGroup>
</ui:composition>
bean是以下的:
@ManagedBean
@ViewScoped
public class Bean implements Serializable{
private String page;
@PostConstruct
public void init(){
page="registerPage";
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
webapp目录是以下一个(我手工编写,希望我没有错过任何东西)。
web应用
|-- META-INF
|-- WEB-INF
| |-- view
| | -- template
| | |-- template.xhtml
| | |-- menu.xhtml
| | -- registerPage.xthml
| | -- departmentPage.xthml
| | -- healthPage.xthml
| | -- contactsPage.xthml
| |-- app-servlet.xml
| |-- faces-config.xml
| |-- web.xml
|
|-- home.xhtml
例外情况如下:
Dec 29, 2015 11:09:18 PM com.sun.faces.context.PartialViewContextImpl processPartial
INFO: java.lang.NullPointerException
java.lang.NullPointerException
at javax.faces.component.UIComponentBase.getRenderer(UIComponentBase.java:1402)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:785)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1181)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:507)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:377)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:521)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1097)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:448)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:200)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:446)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:271)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:246)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:745)