如何通过ajax(来自菜单)使用jsf2模板进行部分页面渲染(中心内容)

前端之家收集整理的这篇文章主要介绍了如何通过ajax(来自菜单)使用jsf2模板进行部分页面渲染(中心内容)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在努力让这个工作2周,我试图将这两个帖子中的BalusC信息合并到( link1 link2),以通过左边的菜单实现中心内容区域的部分页面渲染.因此,左侧的链接将通过使用< f:ajax>的部分页面呈现来更新中心内容.或者< a4j:ajax>通过richfaces
------------------------------------------------------
| include1 link |                                     |
| include2 link |  center content like include1.xhtml |
| include3 link |                                     |
------------------------------------------------------

我的page-layout.xhtml(include1.xhtml使用的主模板,include2.xhtml,..)看起来像这样.

<h:body>
    <div id="top" class="top">
        <ui:insert name="top">page-layout default top content</ui:insert>
    </div>
    <div>
        <div id="left">
            <h:form id="navigationFormId">             
                    <f:ajax render=":contentForm">                                        
                        <h:commandLink value="include1" 
                                       action="#{navigationBean.setPage('include1')}" />
                        <p></p>
                        <h:commandLink value="include2" 
                                       action="#{navigationBean.setPage('include2')}" />                    
                        <p></p>
                        <h:commandLink value="include3" 
                                       action="#{navigationBean.setPage('include3')}" />   
                        <p></p>
                    </f:ajax>                                     
            </h:form>
        </div>
        <div id="content">
           <ui:insert name="content">

                <h:panelGroup id="contentPanelGroup" layout="block"> 
                    <h:form id="contentForm">

                        <h:panelGroup rendered="#{navigationBean.page == 'include1'}">            
                            <ui:include src="include1.xhtml" />         
                        </h:panelGroup> 
                        <h:panelGroup rendered="#{navigationBean.page == 'include2'}">            
                            <ui:include src="include2.xhtml" />         
                        </h:panelGroup>
                        <h:panelGroup rendered="#{navigationBean.page == 'include3'}">             
                            <ui:include src="include3.xhtml" />         
                        </h:panelGroup>

                    </h:form> 
               </h:panelGroup>     

            </ui:insert>
        </div>
    </div>
</h:body>

NavigationBean.java通过带有@Named的CDI定义为ViewScoped bean

公共类NavigationBean实现Serializable {

public NavigationBean() {}

public String getPage() {return page;}
public void setPage(String p) {page = p;}
private String page = "include1";

}

包含的页面是include1.xhtml和include2.xhtml等文件,当点击左侧菜单链接时应该加载到中心内容,这里是一个示例include2.xhtml

<h:body>

    <ui:composition template="page-template.xhtml">
        <ui:define name="content">

             include2

             <h:form> 
                 form components for include2
             </h:form>

        </ui:define>
    </ui:composition>

</h:body>

我收到FileNotFoundException,虽然堆栈跟踪没有
告诉哪一个,但删除

<h:panelGroup rendered=".....>
    <ui:include src="..." />
</h:panelGroup>

标签删除异常.我认为这是基于2个BalusC帖子实现这一目标的正确实现,但却无法让它发挥作用.

您收到的错误表明无法找到包含… xhtml页面.文件位于何处?它们应该与page-layout.xhtml文件位于同一目录中?为简化一切,我只测试包含是否有效,yuo可以替换为:
<h:form id="contentForm">
        <h:panelGroup rendered="#{navigationBean.page == 'include1'}">            
                <ui:include src="include1.xhtml" />         
        </h:panelGroup> 
        <h:panelGroup rendered="#{navigationBean.page == 'include2'}">            
                <ui:include src="include2.xhtml" />         
        </h:panelGroup>
        <h:panelGroup rendered="#{navigationBean.page == 'include3'}">             
                <ui:include src="include3.xhtml" />         
        </h:panelGroup>
</h:form>

有:

<h:form id="contentForm">
        <ui:include src="include1.xhtml" />         
</h:form>

猜你在找的Ajax相关文章