Primefaces动态包含许多页面

Primefaces动态包含许多页面

本文介绍了如何使用ui:include Primefaces动态包含许多页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我是初学者.

我正在使用Primefaces做一个项目.

I am doing a project using Primefaces.

触发p:menuitem时,我需要动态包含许多页面.

I need to include many pages dynamically when triggering the p:menuitem.

我已经尝试过,但是单击p:menuitem时动态页面并未正确包含,并且该页面仅在刷新页面(浏览器)时显示.

I already tried but the dynamic pages are not included properly when clicked on p:menuitem and that page only show when refresh of the page(browser).

示例代码

<p:menu>
    <p:menuitem action="..." value="Page1"/>
    <p:menuitem action="..." value="Page2"/>
    <p:menuitem action="..." value="Page3"/>
</p:menu>

<p:outputPanel>
    <ui:include src="#{Pages.dynamicaPagesInclude}"/>
</p:outputPanel>

我不知道我在哪里弄错了.

I do not know where I did mistake.

有什么想法吗?

推荐答案

请尝试以下操作:

index.xhtml :此文件是主"页面,该页面包含用于选择要加载的动态页面的菜单.当您在menuItem上按下时,page属性将设置为选定的页面值.然后,一个ajax请求将调用changePage方法,该方法负责设置要加载的页面.我们对menuItem说,我们需要update包含新页面加载的outputPanel才能在浏览器上显示它.

index.xhtml:This file is the "main" page, the page which contains the menu to select the dynamic pages to load.When you press over the menuItem, the page attribute is set to the selected page value. Then, an ajax request invokes to changePage method which is in charge to set the page to load. We say to menuItem that we need to update the outputPanel which contains the new page load to show it on the browser.

<!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:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <title>Test Prime</title>
</h:head>

<h:body>
    <h:form id="formulario">
        <p:menu>
            <p:menuitem value="Page1" actionListener="#{pages.changePage(1)}" update="outputPanel "/>
            <p:menuitem value="Page2" actionListener="#{pages.changePage(2)}" update="outputPanel"/>
        </p:menu>

        <p:outputPanel id="outputPanel">
            <ui:include src="#{pages.dynamicaPagesInclude}" />
        </p:outputPanel>
    </h:form>
</h:body>
</html>

page1.xhtml :虚拟页面,代表一个新页面.

page1.xhtml:Dummy page which represents a new page.

<ui:composition
    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">
    <h2>PAGE 1</h2>
</ui:composition>

page2.xhtml :表示另一个页面的虚拟页面.

page2.xhtml:Dummy page which represents a different page.

<ui:composition
    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">
    <h2>PAGE 2</h2>
</ui:composition>

Pages.java :该Java类是用于控制视图的ManagedBean.它包含一个名为dynamicaPagesInclude的字符串字段,其中包含要加载的页面的路径.方法changePage获取由菜单项设置的属性page.根据其值,选择页面或其他.

Pages.java:This java class is the ManagedBean for controlling the view. It contains a string field called dynamicaPagesInclude with the path of the page to load.The method changePage gets the attribute page which was set by the menuitem. Depending its value, chooses a page or other.

import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;


@ManagedBean
public class Pages {

    private String dynamicaPagesInclude;

    public String getDynamicaPagesInclude() {
        return dynamicaPagesInclude;
    }

    public void setDynamicaPagesInclude(String dynamicaPagesInclude) {
        this.dynamicaPagesInclude = dynamicaPagesInclude;
    }

    public void changePage(int itemSelected ) {
        if (itemSelected == 1) {
            dynamicaPagesInclude = "page1.xhtml";
        } else {
            dynamicaPagesInclude = "page2.xhtml";
        }
    }
}

对不起,我的英语水平.

Sorry for my English level.

这篇关于如何使用ui:include Primefaces动态包含许多页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:32