0

For the start. My Java project uses:

  • NetBeans IDE 8.2
  • Maven -> Web Application
  • Framework: JavaServer Faces 2.2 with PrimeFaces

Other things that I used:

  • Apache Tomcat 8.0.27.0
  • postgresql
  • pgAdmin4

I have searched in many places but I can't find one thing : How to open a page inside other page after click of button. To better describe it below 2 files:

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>

I would like to press the button in the menu (Menu1-> Button1) and open the page (examplePage.xhtml) in the place marked with a comment (index.xhtml).

I can't find the answer how to do it. Can anyone help me?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Beskosty
  • 1
  • 2

1 Answers1

-1

There are two solutions to your project, depending on what you try to do.

If you want to open examplePage.xhtml in the context of index, just use a commandbutton without face-redirect=true

If you want to implement examplePage.xhtml into index.xhtml (logically copying the html content during runtime, or better the components you declare with //Awesome Code here, don't put a second html body in it), you should use a composite.

Follow this tutorial: https://www.mkyong.com/jsf2/composite-components-in-jsf-2-0/

Then you can render the object by setting rendered=true programmatically, therefore follow this questions answers: change rendered attribute from managed bean