【问题标题】:Dynamic rendering of page using p:layout使用 p:layout 动态呈现页面
【发布时间】:2014-05-16 18:36:30
【问题描述】:

我正在尝试根据 p:layout 中的选定操作动态加载页面 - 我的操作由托管 bean 驱动 - 使用下面的代码我看到托管 bean 被调用并且正确的页面被传递但没有得到呈现。想知道我错过了什么,希望有人能指出它。

谢谢

布局页面

  <!DOCTYPE html>
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:p="http://primefaces.org/ui">
      <f:view contentType="text/html" locale="en">
  <h:head title="Title">
        <ui:insert name="head" />
</h:head>
<h:body>
    <p:layout fullPage="true">
        <p:layoutUnit position="north" size="100" header="Top"
             resizable="true" closable="true" collapsible="true">
        </p:layoutUnit>
        <p:layoutUnit position="south" size="100" header="Bottom"
                  resizable="true" closable="true" collapsible="true">
    </p:layoutUnit>
        <p:layoutUnit position="west" size="200" style="width:200px"
               header="Menu" resizable="true" closable="true" collapsible="true">
        <h:form id="formMainMenu">
    <p:panelMenu style="width:400px">
    <p:submenu label="Sub Menu 1">
    <p:submenu label="Sub Menu 2" icon="ui-icon-extlink">
    <p:menuitem value="Option1" 
       actionListener="#{menuController.setPage('../../public/pages/aboutTest.xhtml')}"
         update=":allLayoutForm:allLayout" />
       </p:submenu>
       </p:submenu>
   </p:panelMenu>
   </h:form>
     </p:layoutUnit>


     <p:layoutUnit position="east" size="200" header="Right"
       resizable="true" closable="true" collapsible="true" effect="fade">
 </p:layoutUnit>
 <h:form id="allLayoutForm">
       <p:layoutUnit position="center" id="allLayout">
    <ui:insert name="content">src="#{menuController.page}"</ui:insert>
 </p:layoutUnit>
</h:form>
    </p:layout>
</h:body>
    </f:view>
    </html>

菜单控制器

@SuppressWarnings("unused")
@ManagedBean
@ViewScoped
public class MenuController {

private String page;

public String getPage() {
    System.out.println(" Get "+page);
    return page;
}

public void setPage(String page) {
    System.out.println(page);
    this.page = page;
}

} 

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    如果您需要在应用程序中随处使用 html 页面的某些静态部分,您应该查看 JSF 模板 (example here)。

    MainTemplate.xhtml:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <html xmlns="http://www.w3c.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"
            xmlns:ui="http://java.sun.com/jsf/facelets">
        <h:head>
            <title><ui:insert name="title">Default title</ui:insert></title>
        </h:head>
        <h:body>
            <h:form id="menuForm">
                <p:menubar model="#{bean.menumodel}" />
            </h:form>
            <ui:insert name="content" />
        </h:body>
    </html>
    

    而且你的所有页面看起来都像这样:

    <ui:composition xmlns="http://www.w3c.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"
        xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:cc="http://java.sun.com/jsf/composite" 
        template="/templates/MainTemplate.xhtml">
    
        <ui:define name="title">Title Page</ui:define>
    
        <ui:define name="content">
        /* your jsf code */
        </ui:define>
    </ui:composition>
    

    通过此示例,您可以轻松更改页面的内容和标题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-22
      • 2012-08-21
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 2020-01-26
      • 2012-02-26
      • 1970-01-01
      相关资源
      最近更新 更多