How to change a dynamic content of a template when the user clicks a button?

1

I would like the middle of the page to be changed when the user clicks "login" or "registry". Can someone explain to me how I can do this?

If you know tutorials that teach how to log in and if you can leave the links, I would appreciate it.

PageCode:

<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:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Meu Sistema</title> </h:head> <h:body> <div align="center"> <p:layout style="min-width:1020px;max-width:1020px;min-height:600px"> <p:layoutUnit position="center"> <ui:insert name="centro"> O que estiver aqui será substituido! </ui:insert> </p:layoutUnit> </p:layout> </div> <p:stack icon="imagens/stacks.png" expanded="true"> <p:menuitem value="Login" icon="imagens/lock.png" url="#"/> <p:menuitem value="Registar" icon="imagens/register.png" url="#"/> </p:stack> </h:body> </html>     
asked by anonymous 01.09.2015 / 18:31

1 answer

4

You can do the following:

Define a bean (with @SessionScoped or @ApplicationScoped ) to control which page to display.

And in your xhtml:

<ui:insert name="centro">
    <ui:include src="#{seuBean.pagina}"/>
</ui:insert>

Being pagina (a String) the path of the file.

And when you want to change pages just set the new path in the pagina variable and update the 'center'. Example:

<p:commandLink actionListener="#{seu.trocarParaLogin()}" value="Login"/>

 //método
 public void trocarParaLogin() {
     setPagina("SUA PAGINA");
 }

Possible problems, using this method, you will not have the option to go back / forward in the browser because you are still on the same page. And if you use beans @ViewEscoped they will not be destroyed by changing the content of the 'center'.

    
01.09.2015 / 19:43