简体   繁体   中英

how to navigate to a lot of pages in jsf

I have this problem: I have about 5 pages (could be more...) and a login page and you can always navigate to any page you want from any page you are (except login). So I did a template . I have a

<p:layoutUnit position="north">

in north and another one in the south and other in the west in all the pages (except login) . The west layoutunit has a menu with page1, page2 ... pageN, the north and south have always the same. So what I did is to use a

<ui:include src="norte.xhtml" />

in the north layoutunit and did the same with the south and west layoutunit. But the problem is that i can navigate from any page to any page so how can i manage this navigation situation? Do i have to create navigation rules for all the possible navigation situations?

Please help me. I want to make this dynamic. I am using JavaEE 7, JSF 2.2 with PrimeFaces 4.0 and Netbeans. I want to do this in the most correct way possible.

Do i have to use forward or redirect and how do I do it?

This is the menu code:

<h:body>
        <ui:composition>
            <p:menu>
                <p:menuitem value="Inicio" action="page1" />
                <p:menuitem value="Altas / Entradas" action="page2" />
                <p:menuitem value="Modificar Refacciones" action="page3" />
                <p:menuitem value="Consultar" action="page4" />
            </p:menu>
        </ui:composition>
    </h:body>
  • Thanks for Your help :)

You need to use:

<ui:insert name="content"/>

in the template.. Than every page you want to use the template you need to wrap in

<ui:composition template="/yourpath/yourtemplatePage"/>
     <ui:define name="content">
     bla bla
     <ui:define/>
<ui:composition/>

Here is a basic explain of jsf templatingL http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/

And another one: http://courses.coreservlets.com/Course-Materials/pdf/jsf/jsf2/JSF2-Facelets-Templating.pdf

Hope that help :).

EDIT:

I will give a little bit more here: Lets say you have the following pages: index.jsf,page1.jsf,page2.jsf.

You need to create template with the menu for example: template.jsf:

 <h:body>
   <p:menu>
     <p:menuitem value="Inicio" action="/appname/index?faces-redirect=true" />
     <p:menuitem value="Altas / Entradas" action="/appname/page1" />
     <p:menuitem value="Modificar Refacciones" action="/appname/page2" />
   </p:menu>
   <ui:insert name="pageContent"/>
 </h:body>

As you can see i added ?faces-redirect=true, This will replace the forward with redirect.. You can do it whenever you want to redirect instead of forward. Now for example index.jsf:

<ui:composition template="/appname/template.xhtml"/>
     <ui:define name="contentPage">
        i am index page
     <ui:define/>
<ui:composition/>

The same will be on page1,page2 only their content will be change.

Now all the pages will contain the same menu.. And the menu will be defined only in the template. When you can the path to the page in your app it will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM