菜单操作后在另一个页面中打开页面

时间:2019-08-11 04:35:21

标签: jsf primefaces

首先。我的 Java 项目使用:

  • NetBeans IDE 8.2
  • Maven -> Web应用程序
  • 框架: JavaServer Faces 2.2与 PrimeFaces

我使用过的其他东西:

  • Apache Tomcat 8.0.27.0
  • postgresql
  • pgAdmin4

我在很多地方搜索过,但找不到一件事:单击按钮后如何在其他页面内打开页面。为了更好地描述以下2个文件:

index.xhtml

<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:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">

<f:view contentType="text/html">
    <h:head>
        <f:facet name="first">
            <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
            <title>MY AWESOME PAGE</title>
        </f:facet>
    </h:head>

    <h:body>
        <p:layout fullPage="true">
            <p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true">
                HEADER
            </p:layoutUnit>
            <p:layoutUnit position="west" size="250" header="Menu" collapsible="true">
                <h:form>
                    <p:growl>
                        <p:autoUpdate />
                    </p:growl>
                    <p:panelMenu style="width:300px">
                        <p:submenu label="Menu1">
                            <p:menuitem value="Button1"/>
                            <p:menuitem value="Button2"/>
                        </p:submenu>
                        <p:submenu label="Menu2">
                            <p:menuitem value="Button1"/>
                            <p:menuitem value="Button2"/>
                        </p:submenu>
                        <p:separator />
                        <p:submenu label="Menu3">
                            <p:menuitem value="Button1"/>
                            <p:menuitem value="Button2"/>
                        </p:submenu>
                    </p:panelMenu>
                </h:form>
            </p:layoutUnit>

            <p:layoutUnit position="center">
                <h:form>
                        <!--
                        Place where i wanna open page
                        -->
                </h:form>
            </p:layoutUnit>
        </p:layout>
    </h:body>
</f:view>
</html>

examplePage.xhtml

<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">

  <h:head>
  </h:head>

  <h:body>
    SOME AWESOME CODE HERE
  </h:body>
</html>

我想按菜单(Menu1-> Button1)中的按钮,然后在标有注释(index.xhtml)的位置打开页面(examplePage.xhtml)。

我找不到解决方法。谁能帮我吗?

1 个答案:

答案 0 :(得分:-1)

根据您要执行的操作,您的项目有两种解决方案。

如果要在索引的上下文中打开examplePage.xhtml,只需使用不带face-redirect = true的命令按钮

如果您想将examplePage.xhtml实现为index.xhtml(在运行时逻辑上复制html内容,或者更好地使用// Awesome Code声明的组件,请不要在其中放置第二个html主体),应该使用复合材料。

遵循本教程:https://www.mkyong.com/jsf2/composite-components-in-jsf-2-0/

然后您可以通过以编程方式设置render == true来呈现对象,因此请遵循以下问题答案:change rendered attribute from managed bean