JSF 2.0 substituir PanelGrid dinamicamente[RESOLVIDO]

2 respostas
rafabh3

Bom dia pessoal!!!

Sou iniciante no jsf, e estou com uma dúvida. Eu tenho uma tela com um panelGrid que me mostra vários registros de uma tabela do banco. Tenho também um campo de busca onde eu busco pelo nome do registro e um novo panelGrid é renderizado com os resultados da busca. A minha dúvida é:

Como eu faço para que o primeiro panelGrid desapareça e o segundo panel com o resultado da busca entre no lugar dele. Do jeito que está aqui, o panelGrid de busca é renderizado em cima do outro panel e entao, ficam os dois na tela ao mesmo tempo, quando deveria ficar só um.

Aí vai meu xhtml para ficar mais claro.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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:rich="http://richfaces.org/rich">
    <h:head>
        <title>GA - Pré-tarefas Cadastradas</title>
    </h:head>
    <h:body>
        <h:panelGroup id="preTarefaWrapper">
            <h:form>
                <h:outputText value="Pré-tarefas Cadastradas"/>
                <br/>
                <br/>
                &lt;h:outputText value="Filtro por nome"/&gt;<br/>
                &lt;h:inputText value="#{preTarefaController.nome}"/&gt;
                <br/>
                &lt;h:commandButton action="#{preTarefaController.buscarPorNome}" value="Filtrar"&gt;
                  
                &lt;/h:commandButton&gt;
                <br/>
                    <br/>
                    &lt;h:panelGroup rendered="#{not empty preTarefaController.buscaPorNomeList}"&gt;
                        &lt;h:panelGrid columns="2" border="0" rules="rows"&gt;
                        &lt;f:facet name="header"&gt;
                            &lt;h:outputText value="Pré-Tarefas"/&gt;
                        &lt;/f:facet&gt;
                            
                                &lt;ui:repeat var="preTarefa" value="#{preTarefaController.buscaPorNomeList}"&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                            &lt;h:outputText value="#{preTarefa.nome}"/&gt;&nbsp;
                                &lt;/td&gt;
                                &lt;td&gt;
                                    <a >Editar</a>&nbsp;
                            &lt;h:commandLink value="Excluir"&gt;
                                &lt;rich:componentControl target="popup" operation="show" /&gt;
                            &lt;/h:commandLink&gt;
                            <br/>
                                &lt;/td&gt;
                            &lt;/tr&gt;
                                &lt;rich:popupPanel id="popup" modal="true" autosized="true" resizeable="false"&gt;
                                &lt;f:facet name="header"&gt;
                                    &lt;h:outputText value="Excluir Pré-Tarefa" /&gt;
                                &lt;/f:facet&gt;
                                <p>
                                    &lt;h:form&gt;
                                    &lt;h:outputText value="Deseja realmente excluir esta pré-tarefa?"/&gt;<br/><br/>
                                    &lt;h:commandButton id="excluir" onclick="#{rich:component('popup')}.hide()" value="Sim"&gt;
                                        &lt;f:ajax listener="#{preTarefaController.remover(preTarefa)}" render=":preTarefaWrapper"/&gt;
                                    &lt;/h:commandButton&gt;
                                    &lt;h:message for="excluir"/&gt;&nbsp;&nbsp;
                                    &lt;h:commandButton id="excluirTarefa" onclick="#{rich:component('popup')}.hide()" value="Não"/&gt;
                                    &lt;/h:form&gt;
                                </p>
                                &lt;/rich:popupPanel&gt;
                            &lt;/ui:repeat&gt;
                        &lt;/h:panelGrid&gt;
                    &lt;/h:panelGroup&gt;
                    <br/>
                        &lt;h:panelGroup rendered="#{not empty preTarefaController.preTarefaList}"&gt;
                            &lt;h:panelGrid columns="2" border="0" rules="rows"&gt;
                        &lt;f:facet name="header"&gt;
                            &lt;h:outputText value="Pré-Tarefas" /&gt;
                        &lt;/f:facet&gt;
                            
                                &lt;ui:repeat var="preTarefa" value="#{preTarefaController.preTarefaList}"&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                            &lt;h:outputText value="#{preTarefa.nome}"/&gt;&nbsp;
                                &lt;/td&gt;
                                &lt;td&gt;
                                    <a >Editar</a>&nbsp;
                            &lt;h:commandLink value="Excluir"&gt;
                                &lt;rich:componentControl target="popup" operation="show" /&gt;
                            &lt;/h:commandLink&gt;
                            <br/>
                                &lt;/td&gt;
                            &lt;/tr&gt;
                                &lt;rich:popupPanel id="popup" modal="true" autosized="true" resizeable="false"&gt;
                                &lt;f:facet name="header"&gt;
                                    &lt;h:outputText value="Excluir Pré-Tarefa" /&gt;
                                &lt;/f:facet&gt;
                                <p>
                                    &lt;h:form&gt;
                                    &lt;h:outputText value="Deseja realmente excluir esta pré-tarefa?"/&gt;<br/><br/>
                                    &lt;h:commandButton id="excluir" onclick="#{rich:component('popup')}.hide()" value="Sim"&gt;
                                        &lt;f:ajax listener="#{preTarefaController.remover(preTarefa)}" render=":preTarefaWrapper"/&gt;
                                    &lt;/h:commandButton&gt;
                                    &lt;h:message for="excluir"/&gt;&nbsp;&nbsp;
                                    &lt;h:commandButton id="excluirTarefa" onclick="#{rich:component('popup')}.hide()" value="Não"/&gt;
                                    &lt;/h:form&gt;
                                </p>
                                &lt;/rich:popupPanel&gt;
                            &lt;/ui:repeat&gt;
                        &lt;/h:panelGrid&gt;
                    &lt;/h:panelGroup&gt;
                &lt;h:panelGroup rendered="#{empty preTarefaController.preTarefaList}"&gt;
                    &lt;h:outputText value="Nenhuma pré-tarefa encontrada."/&gt;
                &lt;/h:panelGroup&gt;
            &lt;/h:form&gt;
        &lt;/h:panelGroup&gt;
    &lt;/h:body&gt;
&lt;/html&gt;

Agradeço desde já quem puder me dar uma ajuda com isso!!! Obrigado!!

2 Respostas

A

cara,

so vc usar rendered, e crie um boolean no seu MB para vc fazer controle de qual vc quer mostrar.

t+

rafabh3

Olá alisson, muito obrigado pela atençao, eu resolvi o problema utilizando o rendered, mas nao precisei criar boolean no MB, apenas setei uma condiçao “and” no rendered do panelGroup que tras os registros no banco.

Para quem tiver o mesmo problema, a linha 63 ficou dessa forma:

&lt;h:panelGroup rendered="#{not empty preTarefaController.preTarefaList and empty preTarefaController.buscaPorNomeList}"&gt;

Um abraço a todos.

Criado 27 de outubro de 2011
Ultima resposta 27 de out. de 2011
Respostas 2
Participantes 2