0

What I want: click a button and load a filtered datatable (located in another xhtml file), based on the parameter used to calculate the amount displayed in such button.

In a index.jsf has a form with 3 buttons which displays the amount of registers in a table obtained from querying to a database through the controller class:

<h:form id="kpiForm">
    <p:panel id="kpiPanel" >
        <p:button id="bt1" value="#{demandasController.amountX}" />
        <p:button id="bt2" value="#{demandasController.amountY}" />
        <p:button id="bt3" value="#{demandasController.amountZ}" outcome="/app/demandas/index" /> <!-- clicking this button loads the page with the datatable, but not filtered.
    </p:panel>
</h:form>

The controller class has the properties which returns the amount values (just to be short, I'll show only methods related to amount X.):

public String getAmountX() {
    return LoadAmountX().toString();
}

//setter ommited

private List<Demandas> LoadAmountX() {
        List<Demandas> listAmountX = DemandasFacade.findAmountX();
        return listAmountX;
    }

In my facade I have:

public List<Demandas> findAmountX() {
        return (List<Demandas>) getEntityManager().createNamedQuery("Demandas.findAmountX", Demandas.class).getResultList();
    }

And in my entity class I have the named queries:

@NamedQuery(name = "Demandas.findAmountX", query = "SELECT COUNT(d.id) FROM Demandas d WHERE d.situacao.idSituacao = 3"),

In datatable I have a column which contains the values for such parameters:

<ui:composition>
<h:form id="DemandasListForm">    
    <p:panel id="PanelListForm" header="#{adeBundle.ListDemandasTitle}">

        <p:dataTable id="datalist"
                     value="#{demandasController.items}"
                     rowKey="#{item.id}"
                     var="item"
                     selection="#{demandasController.selected}"
                     filteredValue="#{demandasController.filteredDemandas}"
                     widgetVar="demandasTable">

            <!-- some columns ommited -->

            <p:column sortBy="#{item.id}" filterBy="#{item.id}" >
                <f:facet name="header">
                    <h:outputText value="id"/>
                </f:facet>
                <h:outputText value="#{item.id}"/>
            </p:column>    

            <p:column sortBy="#{item.status.status}" filterBy="#{item.status.status}" filterMatchMode="in" >
                <f:facet name="filter">
                    <p:selectCheckboxMenu label="Status" onchange="PF('demandasTable').filter()" >
                        <f:selectItems value="#{demandasController.statusListCombo}" />
                    </p:selectCheckboxMenu>
                </f:facet>
                <h:outputText value="#{item.status.status}"/>
            </p:column>    
        </p:dataTable>

    </p:panel>
</h:form>
</ui:composition>

I've researched to try to resolved it, but I don't know how to do it:

Can someone, please, help me ?

jMarcel
  • 958
  • 5
  • 24
  • 54

1 Answers1

0

After long researching, found a simple solution using JQuery:

In some index.xhtml:

<ui:composition>
  <h:form id="kpiForm">
    <p:panel id="kpiPanel" >
      <p:commandButton value="filter 1" action="/app/index" oncomplete=" $('#MyFormID\\:MyDatatableID\\:BoxID\\:1').click(); PF('wv').filter();" />
      <p:commandButton value="filter 2" action="/app/index" oncomplete=" $('#MyFormID\\:MyDatatableID\\:BoxID\\:2').click(); PF('wv').filter();" />
      <p:commandButton value="filter 3" action="/app/index" oncomplete=" $('#MyFormID\\:MyDatatableID\\:BoxID\\:3').click(); PF('wv').filter();" />
    </p:panel>
  </h:form>
</ui:composition>

In another.xhtml:

<!-- some code ommited -->
<ui:composition [...]>
  <h:form id="OutsideFormID">
    <p:panel id="MyPanelID" header="Some Title">

      <p:dataTable id="MyDatatableID"
    value="#{datatableController.items}"
    rowKey="#{item.id}"
    var="item"
    selection="#{datatableController.selected}"
    filteredValue="#{datatableController.filteredDemandas}"
    widgetVar="wv">

          <p:column id="MyColumnID" sortBy="#{item.status.statusName}" filterBy="#{item.status.statusName}" filterMatchMode="in" >
            <f:facet name="header">
                <h:outputText value="STATUS"/>
            </f:facet>
            <f:facet name="filter">
            <p:selectCheckboxMenu id="BoxID" widgetVar="BoxWV" label="status" onchange="PF('wv').filter()">
                <f:selectItems id="ComboID" value="#{datatableController.statusListCombo}" />
            </p:selectCheckboxMenu>
            </f:facet>
            <h:outputText value="#{item.status.statusName}"/>
        </p:column>
      </p:dataTable>
    </p:panel>
  </h:form>
</ui:composition>
jMarcel
  • 958
  • 5
  • 24
  • 54