Data Table Primefaces - jsf

I'm working with JSF Primefaces and I want to make a search and show results in but results won't show, I'm doing this with Result type and had implemented like this in JSF 2.1 whith MyFaces tomahawk, but now with primefaces this doesn't work, here is my code
<h:form id="buscar_sucursal">
<p:panel style="width: 800px">
<h:panelGrid columns="5">
<h:outputText value="Criterio: " />
<p:selectOneMenu id="citerio" value="#{SucursalesBean.criterio}">
<f:selectItem itemValue="1" itemLabel="CVE SUCURSAL"></f:selectItem>
<f:selectItem itemValue="2" itemLabel="NOMBRE"></f:selectItem>
</p:selectOneMenu>
<h:outputText value="Valor: " />
<p:inputText id="valor" value="#{SucursalesBean.valor}"></p:inputText>
<p:commandButton action="#{SucursalesBean.buscar}" value="Buscar"></p:commandButton>
</h:panelGrid>
</p:panel>
<p:dataTable id="sucursalesTable" var="suc" value="#{SucursalesBean.sucursalesTable}">
<p:column headerText="Id">
<h:outputText value=""></h:outputText>
</p:column>
<p:column headerText="Cve">
<h:outputText value="#{suc.cve_sucursal}"></h:outputText>
</p:column>
<p:column headerText="Sucursal">
<h:outputText value="#{suc.sucursal}"></h:outputText>
</p:column>
<p:column headerText="Domicilio">
</p:column>
<p:column headerText="Contraseña">
</p:column>
<p:column headerText="Accion">
<h:commandLink value="Editar"></h:commandLink> /
<h:commandLink value="Eliminar"></h:commandLink>
</p:column>
</p:dataTable>
</h:form>
And the code of my ManagedBean
public Result getSucursalesTable()
{
return this.sucursalesTable;
}
public void setSucursalesTable(Result sucursalesTable)
{
this.sucursalesTable = sucursalesTable;
}
public void buscar() throws ClassNotFoundException
{
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
this.valor = request.getParameter("buscar_sucursal:valor");
try
{
LoginBean loginBean = (LoginBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("LoginBean");
Connection conn = loginBean.getConectar_db();
//int id_empresa = loginBean.getId_empresa();
ArrayList<SucursalesBean> al = new ArrayList<SucursalesBean>();
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
//ResultSet rs = st.executeQuery("SELECT *FROM clientes WHERE id_cliente='"+request.getParameter("id_cliente")+"';"); // AND id_contribuyente='' AND id_empresa=''
//if(request.getParameter("sucursales:id_sucursal") != null)
//rs = st.executeQuery("SELECT *FROM sucursales WHERE id_sucursal='"+request.getParameter("sucursales:id_sucursal")+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';"); // AND id_contribuyente='' AND id_empresa=''
if(getCriterio().toString() != null)
{
if(getCriterio().toString().equals("1"))
rs = st.executeQuery("SELECT cve_sucursal,sucursal FROM sucursales WHERE cve_sucursal='"+this.valor+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
if(getCriterio().toString().equals("2"))
rs = st.executeQuery("SELECT *FROM sucursales WHERE sucursal LIKE '%"+this.valor+"%' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
}
this.sucursalesTable = ResultSupport.toResult(rs);
//this.sucursalesTable = rs;
//setSucursalesTable(ResultSupport.toResult(rs));
/*while(rs.next())
{
//out.println("<tr><td>"+rs.getString("sucursal")+"</td><td>"+rs.getString("cve_sucursal")+"</td><td>"+rs.getString("telefono")+"</td><td>"+rs.getString("e_mail")+"</td><td>"+rs.getString("calle")+"</td><td><a href='sucursales.jsp?accion=editar&id_sucursal="+rs.getString("id_sucursal")+"'>Editar</a></td><td></td></tr>");
//setId_sucursal(String.valueOf(rs.getInt("id_sucursal")));
setCve_sucursal(rs.getString("cve_sucursal"));
setSucursal(rs.getString("sucursal"));
al.add(this);
}
this.sucursalesTable = al;*/
}
catch(SQLException ex)
{
}
}
I don't want to use serialized objects in order to use List type because I think it's to much code for doing something that supposed to be simple, even if this it's not the best aproach.
My doubt it's if Primefaces has support for Result type or am I lost with this and maybe that's why this aproach isn't working.
Any help I really appreciate thank in advance

It looks to me as you've converted a h:commandButton to p:commandButton. The first by default uses non-ajax request, but the latter uses an ajax request. If correct, you just need to tell the button which components to process during and update after the request:
<p:commandButton action="#{SucursalesBean.buscar}"
value="Buscar"
process="criterio valor"
update="sucursalesTable" />
Or use a non-ajax request:
<p:commandButton action="#{SucursalesBean.buscar}"
value="Buscar"
ajax="false" />

Related

Show dynamically tooltip after mouseon event in jsf

I am trying to show tooltip dynamically after mouseon event in JSF. Also I need to call a java method on mouseon event in datatable row.
Here what I have tried:
<p:ajax event="mouseover" actionListener="#{buyerWalletView.testMethod)}"/>
public void testMethod(ActionEvent ev) throws IOException {
if (ev.getSource() != null && ev.getSource() instanceof HtmlDataTable) {
HtmlDataTable objHtmlDataTable = (HtmlDataTable) ev.getSource();
System.out.println(objHtmlDataTable.getRowIndex());
}
}
// for tooltip:
<p:column width="150">
<f:facet name="header">
<h:outputText value="#{lbl['wallet.platform']}" />
</f:facet>
<h:outputText value="#{cartItem.platformType}"/>
<p:tooltip for="walletHistoryTable"
value="test"/>
</p:column>
Thanks in advance.

p:dataTable filtered, sorted, paginated results get displayed in a single row

I'm working on a theme for an app I'm making with PrimeFaces 6.2 (community edition) and I'd like to get my simulated DAO objects working before I proceed with my css templating.
I've got an issue I came across in the past and I can't find the right answer for it again. Would someone point out an error I've made somewhere in my code?
Details:
I've made a somewhat complex DataTable using PrimeFaces LazyDataModel with little help from PrimeFaces Showcase pages. My main issue is, when I write something in the filter fields or click on any column headers to do data sorting or even click on pagination buttons I get an unexpexted data rendering issue.
Filtered, sorted and paginated results get displayed in a single concatenated row what I don't want. I've posted images and code further below for insight.
Also, I'd like to point out:
No exceptions in JS console.
No exceptions in Java console.
don't mind the missing pagination icons (text-indent: 0;)
XHTML:
<h:form id="input-form-dt2">
<H4>DATA TABLE - LAZY MODEL</H4>
<div class="flex-container">
<p:outputPanel id="dev-input-panel-13">
<p:dataTable var="DOTable" value="#{dtModelLazy.DOTList}" paginator="true" rows="10" rowKey="#{DOTable.userID}"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15,25,50" selectionMode="single" selection="#{dtModelLazy.selectedObj}" id="DTModelB" lazy="true">
<p:ajax event="rowSelect" listener="#{dtModelLazy.onRowSelect}" update="input-form-dt2:dlgDTOObjDetail" oncomplete="PF('DTObjDialog').show()" />
<p:column headerText="User ID" sortBy="#{DOTable.userID}" filterBy="#{DOTable.userID}" filterMatchMode="contains">
<h:outputText value="#{DOTable.userID}" />
</p:column>
<p:column headerText="Name" sortBy="#{DOTable.name}" filterBy="#{DOTable.name}" filterMatchMode="contains">
<h:outputText value="#{DOTable.name}" />
</p:column>
<p:column headerText="Surname" sortBy="#{DOTable.surname}" filterBy="#{DOTable.surname}" filterMatchMode="contains">
<h:outputText value="#{DOTable.surname}" />
</p:column>
<p:column headerText="Age" sortBy="#{DOTable.age}" filterBy="#{DOTable.age}" filterMatchMode="contains">
<h:outputText value="#{DOTable.age}" />
</p:column>
<p:column headerText="Address" sortBy="#{DOTable.address}" filterBy="#{DOTable.address}" filterMatchMode="contains">
<h:outputText value="#{DOTable.address}" />
</p:column>
<p:column headerText="City" sortBy="#{DOTable.city}" filterBy="#{DOTable.city}" filterMatchMode="contains">
<h:outputText value="#{DOTable.city}" />
</p:column>
<p:column headerText="Post code" sortBy="#{DOTable.postCode}" filterBy="#{DOTable.postCode}" filterMatchMode="contains">
<h:outputText value="#{DOTable.postCode}" />
</p:column>
<p:column headerText="Country code" sortBy="#{DOTable.countryCode}" filterBy="#{DOTable.countryCode}" filterMatchMode="contains">
<h:outputText value="#{DOTable.countryCode}" />
</p:column>
<p:column headerText="Phone number" sortBy="#{DOTable.phoneNumber}" filterBy="#{DOTable.phoneNumber}" filterMatchMode="contains">
<h:outputText value="#{DOTable.phoneNumber}" />
</p:column>
<p:column headerText="Avatar hash" sortBy="#{DOTable.photoID}" filterBy="#{DOTable.photoID}" filterMatchMode="contains">
<h:outputText value="#{DOTable.photoID}" />
</p:column>
</p:dataTable>
<p:dialog id="dlgDTOObjDetail" header="DataTable Object Detail" widgetVar="DTObjDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="DTObjDetail">
<p:panelGrid columns="2" rendered="#{not empty dtModelLazy.selectedObj}" columnClasses="label,value">
<h:outputText value="User ID: " />
<h:outputText value="#{dtModelLazy.selectedObj.userID}" />
<h:outputText value="Name: " />
<h:outputText value="#{dtModelLazy.selectedObj.name}" />
<h:outputText value="Surname: " />
<h:outputText value="#{dtModelLazy.selectedObj.surname}" />
<h:outputText value="Age: " />
<h:outputText value="#{dtModelLazy.selectedObj.age}" />
<h:outputText value="Address: " />
<h:outputText value="#{dtModelLazy.selectedObj.address}" />
<h:outputText value="City: " />
<h:outputText value="#{dtModelLazy.selectedObj.city}" />
<h:outputText value="Post code: " />
<h:outputText value="#{dtModelLazy.selectedObj.postCode}" />
<h:outputText value="Country code: " />
<h:outputText value="#{dtModelLazy.selectedObj.countryCode}" />
<h:outputText value="Phone number: " />
<h:outputText value="#{dtModelLazy.selectedObj.phoneNumber}" />
<h:outputText value="Photo hash: " />
<h:outputText value="#{dtModelLazy.selectedObj.photoID}" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</p:outputPanel>
</div>
<hr></hr>
</h:form>
LAZY MODEL:
public class DataTableModelLazy extends LazyDataModel<DODataTable> {
private static final long serialVersionUID = -2647349397077805782L;
private List<DODataTable> datasource;
public DataTableModelLazy(List<DODataTable> datasource) {
this.datasource = datasource;
}
#Override
public DODataTable getRowData(String rowKey) {
for(DODataTable dtObj : datasource) {
if(dtObj.getUserID().equals(rowKey))
return dtObj;
}
return null;
}
#Override
public Object getRowKey(DODataTable dtObj) {
return dtObj.getUserID();
}
#Override
public List<DODataTable> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,Object> filters) {
List<DODataTable> data = new ArrayList<DODataTable>();
//filter
for(DODataTable dtObj : datasource) {
boolean match = true;
if(filters != null) {
for (Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
try {
String filterProperty = it.next();
Object filterValue = filters.get(filterProperty);
Field field = dtObj.getClass().getDeclaredField(filterProperty);
field.setAccessible(true);
String fieldValue = String.valueOf(field.get(dtObj));
field.setAccessible(false);
if(filterValue == null || fieldValue.startsWith(filterValue.toString())) {
match = true;
} else {
match = false;
break;
}
} catch(Exception e) {
match = false;
}
}
}
if(match) {
data.add(dtObj);
}
}
//sort
if(sortField != null) {
Collections.sort(data, new DataTableModelLazySorter(sortField, sortOrder));
}
//rowCount
int dataSize = data.size();
this.setRowCount(dataSize);
//paginate
if(dataSize > pageSize) {
try {
return data.subList(first, first + pageSize);
} catch(IndexOutOfBoundsException e) {
return data.subList(first, first + (dataSize % pageSize));
}
} else {
return data;
}
}
}
VIEW BEAN:
#Named("dtModelLazy")
#ViewScoped
public class DataGeneratorBeanLazy implements Serializable {
private static final long serialVersionUID = -5918527333909822277L;
private LazyDataModel<DODataTable> DOTList;
private DODataTable selectedObj;
#Inject
private DataGeneratorBean dataGen;
#PostConstruct
public void init() {
DOTList = new DataTableModelLazy(dataGen.createDTObjects(1500));
}
public LazyDataModel<DODataTable> getDOTList() {
return DOTList;
}
public void setDOTList(LazyDataModel<DODataTable> dOTList) {
DOTList = dOTList;
}
public void onRowSelect(SelectEvent event) {
FacesMessage msg = new FacesMessage("DataTable object selected!", ((DODataTable) event.getObject()).getUserID());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public DODataTable getSelectedObj() {
return selectedObj;
}
public void setSelectedObj(DODataTable selectedObj) {
this.selectedObj = selectedObj;
}
}
Update 1
I have modified the update property as update="input-form-dt2:dlgDTOObjDetail"to meet the suggestion provided. Also, I added the id property for the dialog. The issue still remains.
Update 2
I've changed my approach and started with the basic DataTable first. Also, I've stripped the .xhtml to a bare minimum. It contains only a form with the DataTable inside like so:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<div>
UI components design
</div>
<h:form id="input-form-dt1">
<h4>DATA TABLE - BASIC</h4>
<p:dataTable id="DTableA" var="dataObject" value="#{dataTableBean.objectList}" paginator="true" rows="10" rowKey="#{dataObject.id}"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15,25,50">
<p:column headerText="User ID" sortBy="#{dataObject.userID}" filterBy="#{dataObject.userID}" filterMatchMode="contains">
<h:outputText value="#{dataObject.userID}" />
</p:column>
<p:column headerText="Name" sortBy="#{dataObject.name}" filterBy="#{dataObject.name}" filterMatchMode="contains" >
<h:outputText value="#{dataObject.name}" />
</p:column>
<p:column headerText="Surname" sortBy="#{dataObject.surname}" filterBy="#{dataObject.surname}" filterMatchMode="contains" >
<h:outputText value="#{dataObject.surname}" />
</p:column>
<p:column headerText="Age" sortBy="#{dataObject.age}" filterBy="#{dataObject.age}" filterMatchMode="contains" >
<h:outputText value="#{dataObject.age}" />
</p:column>
<p:column headerText="Address" sortBy="#{dataObject.address}" filterBy="#{dataObject.address}" filterMatchMode="contains" >
<h:outputText value="#{dataObject.address}" />
</p:column>
<p:column headerText="City" sortBy="#{dataObject.city}" filterBy="#{dataObject.city}" filterMatchMode="contains" >
<h:outputText value="#{dataObject.city}" />
</p:column>
<p:column headerText="Post code" sortBy="#{dataObject.postCode}" filterBy="#{dataObject.postCode}" filterMatchMode="contains" >
<h:outputText value="#{DOTable.postCode}" />
</p:column>
<p:column headerText="Country code" sortBy="#{dataObject.countryCode}" filterBy="#{dataObject.countryCode}" filterMatchMode="contains" >
<h:outputText value="#{dataObject.countryCode}" />
</p:column>
<p:column headerText="Phone number" sortBy="#{dataObject.phoneNumber}" filterBy="#{dataObject.phoneNumber}" filterMatchMode="contains" >
<h:outputText value="#{dataObject.phoneNumber}" />
</p:column>
<p:column headerText="Avatar hash" sortBy="#{dataObject.photoID}" filterBy="#{dataObject.photoID}" filterMatchMode="contains">
<h:outputText value="#{dataObject.photoID}" />
</p:column>
</p:dataTable>
</h:form>
</ui:composition>
As you can see I've also removed all event listeners. I've added a new field to my data object (id of type Integer) and bound DataTables rowKey to it (previously bound to userID of type String - not a good idea). My DataTable backing bean is now as basic as it can be:
#Named("dataTableBean")
#ViewScoped
public class DataTableBean implements Serializable {
private static final long serialVersionUID = -1662465661106141910L;
private List<DTObject> objectList;
#Inject
private DataGeneratorBean dataGen;
#PostConstruct
public void init() {
setObjectList(dataGen.createDTObjects(1500));
}
public List<DTObject> getObjectList() {
if (objectList == null) {
return new ArrayList<>();
} else {
return objectList;
}
}
public void setObjectList(List<DTObject> objectList) {
this.objectList = objectList;
}
}
Now, there are no custom filters, sorters or paginators of any type, not even a data model, just raw data objects in a simple list. The output result is exactly the same as before when paginator buttons are clicked or data gets filtered. All resulting data still gets displayed in a single concatenated line.
ANSWER:
As Kukeltje pointed out in the comments I've made a complete nonsense in my main container and added an autoupdate component to it. That component messed up my data table events, loading data without a table to hold it. Once I've removed the component from my main container, everything worked out. Here is the code for my main container (commented out the troublemaker).
<div id="content-window">
<p:outputPanel id="content-panel">
<ui:include src="#{contentLoaderBean.mainContent}" />
<!-- <p:autoUpdate /> -->
</p:outputPanel>
</div>
The only situations I've seen this happening is when the datatable is fully updated in addtion to a partial update of the datatable via an event (page or filter or sort or...) In the rowSelect you do seem to update the full form which contains the datatable as well. That is bad practice and can as mentioned result in what you seem so remove that.
But...in your question there are no filter ajax events that explicitly update the full datatable so that cannot cause it. Yet with 99% vertainty there is something fully updates the datatable. Three options
there is something in your live code you left out of the datatable in your question
There is something else outside the code you posted that plays havoc (an autoupdate e.g),
an update from the server side is being done in a method

Primefaces Datatable unable to select row after ajax update

I'm having what I can call a strange behavior.
I have a page with a panel with several drops downs for search purposes and a datatable in it to display the results.
By default when the page is loaded the values get initialized by a PostContruct init().
I can perform my search without any problem including updating the datatable.
Now, the part where it gets hard for me is the following:
I have a list of tickets with Open/Closed state. My search can be performed with either Open/Closed/ALL.
By default the datatable is loaded with only the open tickets and I can select them and redirect to another page using the selectedRow value.
When I choose to filter by Closed status and I click the button to search, the datatable gets updated I can select the rows but when I try to open any page I get a null pointer exception in the bean.
If I choose all, the datatable gets updated, I can select rows but I can only open the pages with the data that was showed in the first page load, so basically only the tickets that are in the open state. Those that are in Closed that I cannot open them
I'm using RequestScoped bean, I would like to have somehints what could be the problem for the selectRow not work with the new added data.
<ui:define name="content">
<h:form id="searchForm">
<p:panelGrid id="searchPanel" style="width: 1000px" styleClass="ticketsPanel">
<p:row>
<p:column>
<p:outputLabel for="lstStatus" value="Status"></p:outputLabel>
</p:column>
<p:column>
<p:selectOneMenu id="lstStatus" value="#{ticketController.searchStatus}">
<f:selectItem itemValue="Open" itemLabel="Open"></f:selectItem>
<f:selectItem itemValue="Closed" itemLabel="Closed"></f:selectItem>
<f:selectItem itemValue="ALL" itemLabel="ALL"></f:selectItem>
</p:selectOneMenu>
</p:column>
</p:row>
<f:facet name="footer">
<p:row>
<p:column colspan="6" style="alignment-adjust: middle">
<p:commandButton value="Search" action="#{ticketController.search()}" update=":searchForm:lstTicketsTable"></p:commandButton>
<p:commandButton value="Create" action="/tickets/createticket.xhtml?faces-redirect=true"></p:commandButton>
<p:commandButton value="View" action="#{ticketController.doUpdateTicket()}"></p:commandButton>
</p:column>
</p:row>
</f:facet>
</p:panelGrid>
<p:dataTable id="lstTicketsTable" selectionMode="single" paginator="true"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,15,50" rows="10" paginatorPosition="bottom"
value="#{ticketController.ticketList}" selection="#{ticketController.selectedTicket}" var="_tl" rowKey="#{_tl.number}">
<p:column headerText="Ticket NR">
<p:outputLabel value="#{_tl.number}"></p:outputLabel>
</p:column>
<p:column headerText="Summary">
<p:outputLabel value="#{_tl.summary}"></p:outputLabel>
</p:column>
<p:column headerText="Contact From">
<p:outputLabel value="#{_tl.contactfrom}"></p:outputLabel>
</p:column>
<p:column headerText="Researcher">
<p:outputLabel value="#{_tl.researcher.email == null ? '' : _tl.researcher.email}"></p:outputLabel>
</p:column>
<p:column headerText="NSN SR">
</p:column>
<p:column headerText="SR / CR">
</p:column>
<p:column headerText="Release">
<p:outputLabel value="#{_tl.release}"></p:outputLabel>
</p:column>
<p:column headerText="Status">
<p:outputLabel value="#{_tl.status}"></p:outputLabel>
</p:column>
<p:column headerText="Age">
<p:outputLabel value="#{_tl.startdate}"></p:outputLabel>
</p:column>
<p:column headerText="Priority">
<p:outputLabel value="#{_tl.priority}"></p:outputLabel>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
And the backing bean functions doUpdateTicket is the one being called in the View button and the Search the one that updates the list of the datatable.
public void doUpdateTicket() {
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
try {
ec.redirect("/SupportSite/faces/tickets/updateticket.xhtml?tnr=" + this.selectedTicket.getNumber().toString());
} catch (IOException ex) {
Logger.getLogger(TicketController.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void search() {
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
if (this.searchTicketNR != null) {
Ticket t = tjc.findTicket(Integer.parseInt(this.searchTicketNR));
if (t != null) {
try {
//This works when search by ticket number only
ec.redirect("/SupportSite/faces/tickets/updateticket.xhtml?tnr=" + t.getNumber().toString());
} catch (IOException ex) {
Logger.getLogger(TicketController.class.getName()).log(Level.SEVERE, null, ex);
}
}
} else if (this.getSearchStatus() != "ALL") {
setTicketList(tjc.findTicketByStatus(this.getSearchStatus()));
this.init();
} else {
setTicketList(tjc.findTicketEntities());
this.init();
}
}

Request doesn't render response in primefaces datatable

I have a datatable with search field and commandLink to sort. The commandLink that I use to trigger sorting is located not in column header but on the header of datatable. When I load my page and use only commandLink to sort everything works ok. Table sorts in two orders and I see result on my page. Problem appears when I search something in globalFilter. It also works, but after that I cant sort my table. I clear inputText of globalFilter and I cant sort table. To sum up, I see result of sorting only when I not use search field. Sort operation works but request not update the datatable. I put my code below. Maybe somebody knows how to solve it.
<ui:composition>
<p:panel header="Moje pomiary" footer="#{msgs.footer}" id="myMeasurement">
<h:form id="form" prependId="false">
<p:dataTable var="m" value="#{myMeasurementTable.measurement}" id="measureList" editable="true"
widgetVar="mTable"
emptyMessage="No files found with given criteria" filteredValue="#{myMeasurementTable.filteredMeasurement}" >
<f:facet name="header">
Sortowanie według: <p:commandLink id="sortByName" actionListener="#{myMeasurementTable.sortByName}" update="measureList">
<h:outputText value="nazwa pliku" />
</p:commandLink>
|<h:commandLink action="#{myMeasurementTable.sortByArchivisationDate}"> data archiwizacji </h:commandLink>
|<h:commandLink action="#{myMeasurementTable.sortByMeasureDate}"> data badania </h:commandLink>
<p:outputPanel styleClass="searchPanel">
<h:outputText value="Szukaj: " />
<p:inputText styleClass="globalFilter" id="globalFilter" onkeyup="mTable.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column headerText="Informacje pomiarowe" style="width:125px" filterStyle="display:none" filterBy="#{m.fileName} #{m.measureDate} #{m.place} #{m.archivisationDate}"
filterMatchMode="contains" >
<p:separator styleClass="separatorColumn"/>
Nazwa pliku: <h:outputText value="#{m.fileName}" /><br />
Data badania: <h:outputText value="#{m.measureDate}" /><br />
Data archiwzacji: <h:outputText value="#{m.archivisationDate}" /><br />
Miejscowość: <h:outputText value="#{m.place}"/> <br />
Współrzędne GPS:
</p:column>
<p:column headerText="Wykresy">
<img src="/tmp/21/myfile.xls/myfile.xls_Parametr x.png" width="150"/>
</p:column> </p:dataTable></h:form></p:panel></ui:composition>
and part of my bean
#ManagedBean(name = "myMeasurementTable")
#ViewScoped
public class myMeasurementTable implements Serializable{
private static final long serialVersionUID = -9193902657201234669L;
private List<Measurement> measurement;
private List<Measurement> filteredMeasurement;
private boolean sortAscending = true;
public myMeasurementTable() {
measurement = new ArrayList<Measurement>();
fillTable(measurement);
}
public String sortByName() {
System.out.println("naciskam sortowanie");
if (sortAscending) {
Collections.sort(measurement, new Comparator<Measurement>() {
#Override
public int compare(Measurement m1, Measurement m2) {
return m1.getFileName().compareTo(m2.getFileName());
}
});
sortAscending = false;
} else {
Collections.sort(measurement, new Comparator<Measurement>() {
#Override
public int compare(Measurement m1, Measurement m2) {
System.out.println(m2.getFileName());
return m2.getFileName().compareTo(m1.getFileName());
}
});
sortAscending = true;
}
return null;
}
Ok I found solution on primefaces forum. It's simple. I only added oncomplete="mTable.filter()" to commandButton and everything works as I want.

JSF - PrimeFaces , How to get the value of a booleanCheckbox / booleanButton in a list

I have a jsf page that I can't update the value of some checkboxes in a list of userDamain objects, in fact this is a part of my jsf page :
<h:outputText value="USER's rights list: "></h:outputText>
<p:dataTable id="userss" var="userr" value="#{userMB.userListe}">
<p:column>
<f:facet name="header"><h:outputText value="FirstName" /></f:facet>
<h:outputText value="#{userr.firstName}" />
</p:column>
<p:column>
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Basic Usage: " />
<p:selectBooleanCheckbox value="#{userr.deletee}" immediate="true" actionListener="#{userr.deletee}" />
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="dlg.show()" />
<p:dialog header="Selected Values" modal="true" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<h:outputText value="Value 1: #{userr.deletee}" />
</h:panelGrid>
</p:dialog>
</p:column>
when I click on the boolean button 'Submit', the value of the userr.deletee is always false ( the default value ) and it's not updated anyway, I tried to use the Listner and actionListener in the booleanButton but it doesn't work, I also tried the postValidate event, so if someone has any idea of that, I would be graceful.
this is a part of my managed bean:
private List<UserDomain> userListe ;
public List<UserDomain> getUserListe() {
return this.userListe;
}
public void loadUserListe(){
this.userListe = new ArrayList<UserDomain>();
this.userListe.addAll(getUserServicee().getAll());
}
public void setUserListe(List<UserDomain> userListe) {
this.userListe = userListe;
}
a part of the userDomain bean:
...
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Transient
private boolean deletee;
public boolean isDeletee() {
return deletee;
}
public void setDeletee(boolean deletee) {
this.deletee = deletee;
}
I found out a solution which seems logic to me, I added to my checkbox an ajax behavior to execute a method and an attribute which called in this method to get the whole userDomain object, so on I can get the user.deletee value, here is a part of the code I m talking about:
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Delete Right: " />
<p:selectBooleanCheckbox value="#{userr.deletee}">
<f:ajax execute="#this" listener="#{userMB.saveUserRights}" />
<f:attribute name="user" value="#{userr}" />
</p:selectBooleanCheckbox>
</h:panelGrid>
I hope this will be helpful for you

Resources