在p:panels-primefaces中加载xhtml



我有一个问题。我如何使用一个按钮加载一个新的xhtml文件到p:panel,并且仍然改变url。我想使用一个命令按钮来加载一个新的xhtml文件到p:面板,但我仍然希望网站的url改变。

为什么我要这样做

我想这样做,因为我希望我的网站有多个页面与我的工具栏在每个页面。我不想在每个页面中都为我的工具栏复制代码。-这有意义吗?如果有人知道如何帮助,请告诉我。

我的代码。index.xhtml

滚动直到找到p:panel,类值为"ClassPanel"当我的工具栏中的一个按钮被点击时,我希望p:面板加载一个新的xhtml文件。

<!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"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:p="http://primefaces.org/ui" 
       xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
       <title>LEEXV</title>
    </h:head>
    <h:body>
        <style>
        </style>
        <h:form > 
            <p:growl id="messages"/>
            <p:toolbar id="stickymenu" style=" max-height:60px; margin-top: auto; ">
                <f:facet name="left">
                     <f:facet name="left">

                </f:facet>
            <f:facet name="right">
                <p:growl id="growl" life="2000"/>
                <p:inputText  style="margin-right:40px;" placeholder="Search Crawly"/>
                <p:spacer width="10px;"/>
                     <p:commandButton value="Ajax Action" action="#{navigationView.gotoSecond}" style=" width: 90px; height: 40px;"/> 
                <p:spacer width="20px;"  />
                <p:commandButton id="Support" type="ComButton" style=" width: 90px; height: 40px;" value="Donate"/>
                <p:tooltip id="toolTipGrow" for="Support" value="Find out how you can help us help you!"
                           showEffect="clip" hideEffect="explode"  />
                <p:spacer width="20px;"/>
                <p:commandButton type="ComButton" style=" width: 90px; height: 40px;"  value="Update"/>
                <p:spacer width="20px;"/>
                <p:commandButton type="ComButton"   style="width: 90px; height: 40px; margin-top: 6px;"  value="Shop"/>

            </f:facet>


                </f:facet>

                <f:facet name="right">

                </f:facet>

            </p:toolbar>

            <p:sticky target="stickymenu"/>
        </h:form>

        <p:panel class="ClassPanel" >
        <ui:composition id="LoadNewpages"> 
           <ui:param id ="" name="defaultHeader"  value="#{HomeHtml.gotoSecond}" />
      </ui:composition> 

            </p:panel>

    </h:body>
</html>

我的代码。newjsf.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:ui="http://java.sun.com/jsf/facelets"
    xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <body>
        <h:outputText value="hello"/>
   </body>
</html>

我的代码。NavigationView.java

import java.io.Serializable;
 import javax.faces.bean.ManagedBean;
@ManagedBean
public class NavigationView implements Serializable {
    public String gotoSecond() {
        return "newjsf";
    }
}

如果你不明白,请试着帮助我这部分。我有问不好问题的历史

如何使用按钮加载xhtml文件。基本上,我如何动态加载xhtml文件到p:panel。

试试这个,使用include

<p:panel>
    <ui:include src="/page.xhtml"/>
</p:panel>

最新更新