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 ?