【问题标题】:Opening page inside another page after menu action [duplicate]菜单操作后在另一个页面中打开页面[重复]
【发布时间】:2019-08-11 04:35:21
【问题描述】:

首先。我的 Java 项目使用:

  • NetBeans IDE 8.2
  • Maven -> 网络应用程序
  • 框架: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)。

我找不到如何做的答案。谁能帮帮我?

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    您的项目有两种解决方案,具体取决于您尝试执行的操作。

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

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

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

    然后您可以通过设置 render=true 以编程方式渲染对象,因此请按照以下问题回答:change rendered attribute from managed bean

    【讨论】:

      猜你喜欢
      • 2014-08-18
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      相关资源
      最近更新 更多