Manipulating a JSF + Primefaces datatable

Asked

Viewed 243 times

0

How do I make for the dataTable only be displayed after I click Reply Simulated? When loading the page, the dataTable first logo is already displayed, even I have no question in it.

I have a Command Button:

<p:column headerText="Responder Simulado" style="width: 100px; text-align: center">
                        <p:commandButton id="responderSimulado" icon="ui-icon-check" title="Responder Simulado" update="@this :frmCadastroSimulado:exibePerguntas"
                            actionListener="#{responderSimuladoBean.recuperaSimuladoDeAcordoComCicloSelecionado}">
                            <f:param name="ciclo" value="#{ciclo.codigo}"/>
                        </p:commandButton>
</p:column>

And right away, I have a datatable, which updates right after I click reply.

<p:dataTable id="exibePerguntas" var="resposta" paginator="true"
                rowsPerPageTemplate="2,3,5,10,12" paginatorPosition="bottom"  
                value="#{responderSimuladoBean.respostas}"> 
                <p:column headerText="Perguntas">
                    <br></br>
                    <h:outputText escape="false" value="#{resposta.questao.pergunta}"  />

                    <p:selectOneRadio id="resposta" style="width:35%"
                    value="#{resposta.respostaUsuario}">
                    <f:selectItem itemLabel="A" itemValue="A" />
                    <f:selectItem itemLabel="B" itemValue="B" />
                    <f:selectItem itemLabel="C" itemValue="C" />
                    <f:selectItem itemLabel="D" itemValue="D" />
                    <f:selectItem itemLabel="E" itemValue="E" />
                </p:selectOneRadio>

                    <h:outputText value="#{resposta.resultado}" />
                </p:column>
            </p:dataTable>

1 answer

1


How do I make the datatable only appear after I click Reply Simulated?

One way is to use the attribute rendered available in the component datatable (and virtually all JSF components).

Attribute takes a value of type boolean and accepts the use of Expression Language.

A negative value indicates that the component will not be rendered on the page.

In your case, you can use an expression similar to:

<p:dataTable rendered="#{not empty responderSimuladoBean.respostas}" />

There is a very similar example available on showcase do Primefaces.

Browser other questions tagged

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