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

Asked

Viewed 600 times

1

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

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

imagem

Page code:

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

1 answer

4


You can do the following:

Define a bean(com @SessionScoped or @ApplicationScoped) to control which page will be displayed.

And in your xhtml:

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

Being pagina(a String) the file path.

And when you want to change page only set the new path in the variable pagina and update the 'centre'. 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 contents of the 'center'.

  • And as I send the link to the variable page?

  • edited my answer, take a look.

  • I understood everything Voce said but include is not doing the refresh I’m doing so <p:menuitem value="Login" icon="imagens/lock.png" url="#"&#xA; actionListener="#{Controlomenu.Paginalogin}" update="centro" /> in which center and the name of a panelgroup

  • I thought this post answers exactly the question. However, in my opinion, it is not good practice and is not part of the concept of JSF templates.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.