Update primefaces table

Asked

Viewed 599 times

1

Hello, I’m having trouble updating the table after removing some item from it, the item just removed from the table definitely when looking for another type.

The table updates as the value of selects in selectOneMenu.

locationPorType.xhtml

<h:form id="formPrincipal">
    <ui:include src="/WEB-INF/Template/tabelaLayout.xhtml" />

    <p:panelGrid columns="1"
        style="padding-left: 100px; padding-right: 100px;">

        <h:panelGroup>
            <p:outputLabel value="Tipo: " />
            <p:selectOneMenu
                valueChangeListener="#{leiMunicipalMB.colecaoTipo}">
                <f:selectItem itemLabel=" - Selecione um tipo - " itemValue="#{null}" />
                <f:selectItems value="#{leiMunicipalMB.tiposLeis}" var="item"
                    itemValue="#{item.codigo}" itemLabel="#{item.descricao}" />
                <p:ajax update="tabLeisMunicipais" />
            </p:selectOneMenu>
        </h:panelGroup>

        <p:dataTable id="tabLeisMunicipais" var="lei"
            value="#{leiMunicipalMB.leisFiltrarPorTipo}"
            emptyMessage="Nenhuma lei." widgetVar="tabLeisMunicipais"
            reflow="true"
            paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
            rowsPerPageTemplate="5,10,15" paginatorPosition="bottom"
            paginator="true" rows="10">

            ..COLUMNS..


            <p:column style="size: 50px;">
                <p:commandButton id="btnAlterar"
                    icon="fa fa-pencil-square-o fa-1x"
                    action="#{leiMunicipalMB.recebendoLei()}"
                    update=":frmAlterar:panelAlterar"
                    oncomplete="PF('alterarLei').show()" ajax="true">
                    <f:setPropertyActionListener
                        target="#{leiMunicipalMB.leiMunicipal}" value="#{lei}" />
                </p:commandButton>

                <p:commandButton id="btnExcluir" icon="fa fa-trash fa-1x"
                    update=":frmExcluir:panelExcluir"
                    oncomplete="PF('excluirLei').show()">
                    <f:setPropertyActionListener
                        target="#{leiMunicipalMB.leiMunicipal}" value="#{lei}" />
                </p:commandButton>

                <p:commandButton id="btnVisualizar" icon="fa fa-search fa-1x"
                    update=":frmVisualizar:panelVisualizar"
                    oncomplete="PF('visualizarLei').show()" ajax="true">
                    <f:setPropertyActionListener
                        target="#{leiMunicipalMB.leiMunicipal}" value="#{lei}" />
                </p:commandButton>
            </p:column>
        </p:dataTable>

    </p:panelGrid>
</h:form>

modalPanel.xhtml

<p:dialog id="excluirDlg"
    header="Deseja realmente excluir o item abaixo?" widgetVar="excluirLei"
    modal="true" width="auto" draggable="true" location="center" responsive="true">
    <h:form id="frmExcluir">
        <h:panelGrid id="panelExcluir" columns="2" cellpadding="5">

            OutputLabels

            <h:panelGroup>
                <p:commandButton id="btnSim" value="Sim"
                    action="#{leiMunicipalMB.excluirLei}"
                    update="formPrincipal"  
                    onclick="PF('excluirLei').hide()"> 
                    <f:setPropertyActionListener
                        target="#{leiMunicipalMB.leiMunicipal.codigo}"
                        value="#{leiMunicipalMB.leiMunicipal.codigo}" />
                </p:commandButton>
                <p:commandButton id="btnNao" value="Não"
                    onclick="PF('excluirLei').hide()" ajax="true" />
            </h:panelGroup>
        </h:panelGrid>
    </h:form>
</p:dialog>

2 answers

0

In selectOneMenu, try to change your ajax by adding the change:

<p:ajax event="change" update="tabLeisMunicipais" />

0

Sometimes the first faces cannot locate the component when it is inside a dialog or a tab, for example. Try changing the update of your commandButton. It would look like this:

<p:commandButton id="btnSim" value="Sim" action="#{leiMunicipalMB.excluirLei}" update="#{p:component('formPrincipal')}" onclick="PF('excluirLei').hide()"> 
    <f:setPropertyActionListener target="#{leiMunicipalMB.leiMunicipal.codigo}" value="#{leiMunicipalMB.leiMunicipal.codigo}" />
</p:commandButton>
  • Vlw for the help, but the mistake was in Managedbean.

  • I’m glad you decided!

Browser other questions tagged

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