如何使用 Primefaces 动态菜单在 iframe 上加载内容



我有一个页面,我在其中加载我的内容:

  <?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"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:head>
        <meta charset="UTF-8"/>
        <title>Dashboard</title>
        <link rel="stylesheet" type="text/css" href="../css/graficas1_estilos.css" media="all" />           
    </h:head>
    <h:body>
        <div id="page">
            <div id="header">
                <ui:insert name="header" >
                    <ui:include src="Header.xhtml" />
                </ui:insert>
            </div>
            <div id="left">
                <ui:insert name="left" >
                    <ui:include src="Left.xhtml" />
                </ui:insert>
            </div>
            <div id="content">
                <ui:insert name="content" >
                     <iframe scrolling="auto" height="100%" frameborder="0" width="100%" 
                     src="Content.xhtml" name="iFrameMain" id="iFrameMain" pane="center">    
                     </iframe>
                </ui:insert>
            </div>
            <div id="footer">
                <ui:insert name="footer" >
                    <ui:include src="Footer.xhtml" />
                </ui:insert>
            </div>
        </div>
    </h:body>
</html>

在我的左边.xhtml我有我的动态菜单:

<ui:composition>
             <h:form id="dash2">  
         <div class="menu_izquierda">
                         <p:panelMenu id="menuDinamico" model="#{usuariosMB.model}" style="width:200px" styleClass="leftMenu" />
                       </div>
             </h:form>      
    </ui:composition>

最后,为了在我的托管 Bean 中构建我的菜单,我添加:

MenuModel model = new DefaultMenuModel();
DefaultSubMenu inicioMenu = new DefaultSubMenu(Constantes.Inicio);
model.addElement(inicioMenu);
DefaultMenuItem itemD = new DefaultMenuItem(Constantes.Dashboard);
itemD.setOutcome(Constantes.outcome);
inicioMenu.addElement(itemD);

因此,当我单击链接时,它会重新加载整个页面。我应该怎么做,这样只有 iframe 在单击菜单链接后才能重新加载???提前谢谢。

如果你可以使用javascript,

function reloadIframe(e) {
  e.preventDefault();
  document.getElementById('iFrameMain').contentDocument.location.reload(true);
}

并且,在导致问题的链接中,

<button onclick="reloadIframe(event)">Click me</button>

最新更新