Update table primefaces

1

Hello, I'm having trouble updating the table after removing some item from it, the item is only permanently removed from the table when I look for another type.

The table updates as the value of the selected in selectOneMenu .

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

Thank you in advance.

    
asked by anonymous 13.12.2016 / 17:56

2 answers

0

Sometimes primefaces can not find 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>
    
13.12.2016 / 19:09
0

In selectOneMenu, try changing your ajax by adding change:

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