Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 按导航菜单包含内容时出现的问题_Jsf_Jsf 2 - Fatal编程技术网

Jsf 按导航菜单包含内容时出现的问题

Jsf 按导航菜单包含内容时出现的问题,jsf,jsf-2,Jsf,Jsf 2,我目前正在处理一个项目中的问题,我正在使用Spring MVC和Facelets view技术。在我的主模板中,我当前有一个菜单,每当我单击该菜单中的链接时,我的意图是在当前页面中包含另一个页面。我遵循了这个链接,但它并没有解决我的问题。在这个例子中,我默认包含了一个页面,它最初加载,一切看起来都正常,但是当我点击其中一个链接时,我得到了一个空指针异常 我想说的是,我读了很多user@BalusC回复的帖子,但我仍然没有找到解决方案。现在我被困在项目的这一部分,我觉得几乎不可能继续下去 菜单xh

我目前正在处理一个项目中的问题,我正在使用Spring MVC和Facelets view技术。在我的主模板中,我当前有一个菜单,每当我单击该菜单中的链接时,我的意图是在当前页面中包含另一个页面。我遵循了这个链接,但它并没有解决我的问题。在这个例子中,我默认包含了一个页面,它最初加载,一切看起来都正常,但是当我点击其中一个链接时,我得到了一个空指针异常

我想说的是,我读了很多user@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> 
@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;
    }

}
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)
webapp目录如下(我亲手写的,希望没有遗漏任何东西)

网络应用

 |-- 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
例外情况如下:

<?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> 
@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;
    }

}
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)

很抱歉,我不明白你通过“Spring MVC的参与”指的是什么?老实说,我最近很困惑。最初,我想使用SpringMVC+Hibernate+JSF。然后我读到JSF不能算作SpringMVC的视图部分,一种可能是使用SpringMVC+Facelets作为视图部分(这就是我打算做的)。现在我意识到我完全搞砸了,我的最后期限项目快到了。我应该回到jsp并放弃尝试使用Facelets吗?我忘了提到这是我第一次使用Spring。我在这篇文章中读到jsp已被弃用并被Facelets取代,我认为学习它会很好,但老实说,我搞砸了。谢谢你的回答!还有一件事我想问。在我前面提到的帖子中,给出了一个小项目的例子。在这个例子中,我们可以认为Spring MVC和JSF彼此相邻吗?如果是,从什么角度来看?(可能这完全混淆了我)。查看该项目的web.xml时,我有点困惑。在ui:composition下添加h:form,让表单包含所有内容,然后请发布您导入的ViewScope和managedbean@MahendranAyyarsamyKandiar恐怕我只是做了Tiny所说的,我把SpringMVC和JSF混合了起来。我有接收请求的控制器类,我想与Facelets混合,但失败了。我将重新考虑设计。