im working on a project using PrimeFaces 6.0, Mojarra 2.2.9 and on Tomcat 7.
My problem in short is as follows: I use datagrid to display rows retrieved from a db. There is also an option to sort items or filter them. Filter works quite nice, but sorting gives me trouble: If i use the sort option (which is done in the backing bean by DB request), the current page of the datagrid actually displays data in correct order. But if i switch the page, the data is unsorted again. So on every page switch the user has to sort data again. How can i actually force the datagrid component to reload the data from the bean? I tried using ajax with "page" event, but this seems not to fire on page switch, only on data reload via command button. I tried every combination of update, process etc. for commandbutton and datagrid but i cant get it to work.
Also i would like to fetch the data only one time, but that gives me trouble with displaying data: If i fetch the data on pageload (via metadata/view action) the datagrid stays emtpy. It is only filled, if i call the dataload method from a command button, and also only the first page is populated with data. By debug i have seen that actually all data is fetched correctly, but it does not "reach" the datagrid. Any clues what i am doing wrong / what could be better? This lead me to the current not so nice solution which gets the data from the db via getter-Call of the collection, which is the data source for the data grid.
Code of data grid:
Code: Select all
<p:dataGrid var="eh" value="#{personBackingBean.bewerberk}"
columns="1" layout="grid" rows="25" paginator="true" id="dstable"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="Seite {currentPage} von {totalPages}"
rowsPerPageTemplate="10,25,50,100,200,500,1000,2500,5000"
emptyMessage="Keine Ergebnisse gefunden!" lazy="false"
rowIndexVar="Rows">
<p:ajax event="page" listener="#{bewerberBackingBean.loadBewerberK()}"></p:ajax>
....Here comes the displayed data
Code: Select all
<p:commandButton value="Filtern / Sortieren" id="Submit"
ajax="false" update="dstable"
action="#{bewerberBackingBean.loadBewerberK}"></p:commandButton>
Code: Select all
//getter for Data (getPeopleBase returns dataset from DB)
public List<People> getBewerberk() {
System.out.println("loaddata");
bewerberk = getPeopleBase("Köln", "bewerber");
return bewerberk;
}
//Method called after Sort update, but actually does the same
public void loadBewerberK()
{
bewerberk = getPeopleBase("Köln", "bewerber");
System.out.println("Running");
}