I've been working on a jsf project(using primefaces 5.2). I've a datatable which gets updated using a poll in every 10 seconds.I also have a column toggler. Everything is working fine but the only problem is that when poll updates the datatable it again adds all the columns to the table.Is there some way to restrict datatable to only show the selected toggled columns only even after poll update.
Here is My xhtml code
<h:form rendered="#{bean.value!=null}" >
<p:dataTable id="tab" var="var" value="#{bean.value}" >
<f:facet name="header">
Header for dataTable
<p:commandButton style="float:right" id="toggler" type="button" value="Columns" icon="ui-icon-calculator" />
<p:columnToggler datasource="tab" trigger="toggler" />
</f:facet>
<p:column>
<f:facet name="header"><h:outputText value="Start"/>
</f:facet>
<h:outputText value="#{var.startTime}">
<f:convertDateTime pattern="dd.MM.yyyy" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="End"/>
</f:facet>
<h:outputText value="#{var.endTime}" >
<f:convertDateTime pattern="dd.MM.yyyy" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{var.name}" >
</h:outputText>
</p:column>
</p:dataTable>
<p:poll interval="10" update="tab" />
</h:form>
Related
Users just noticed a big bug in my datatable. When you use a datatable and a column toggler, unselecting a column just shift some rows, but it goes wrong when some cells are empty.
So i tried to refresh my data table with
`<p:columnToggler datasource="datalist" trigger="toggler">
<p:ajax event="toggle" update="datalist"/>
</p:columnToggler>`
but it goes wrong with :
`<p:columns value="#{consultationView.columns}" var="column" columnIndexVar="colIndex"
visible="#{column.property.matches('Z06|Z07|Z09')}" >`
Because if i unselected a visible column it makes it visible again...
here is the full datatable :
`
<f:facet name="header">
<p:commandButton process="listFDP" icon="ui-icon-file-pdf" value="Editer les fiches de paie" action="#{consultationView.printPaieAgent()}" escape="false" ajax="false" onclick="this.form.target='_blank'" />
<p:commandButton id="toggler" type="button" value="Colonnes"
style="float:right" icon="ui-icon-calculator" />
<p:columnToggler datasource="datalist" trigger="toggler">
<p:ajax event="toggle" update="datalist"/>
</p:columnToggler>
</f:facet>
<p:column selectionMode="multiple" style="width:16px;text-align:center" exportable="false" toggleable="false" />
<p:column style="width:60px;text-align:left"
sortBy="#{row.gestion.datePaiement}" headerText="Pér. Paie" groupRow="true" sortOrder="ASCENDING" >
<h:outputText value="#{row.gestion.datePaiement}">
<f:converter binding="#{dateConverterMoisAnnee}" />
</h:outputText>
</p:column>
<p:column style="width:60px;text-align:left"
sortBy="#{row.gestion.dateOrigine}" headerText="Pér. Origine">
<h:outputText value="#{row.gestion.dateOrigine}">
<f:converter binding="#{dateConverterMoisAnnee}" />
</h:outputText>
</p:column>
<p:column headerText="N° cont." style="width:25px;text-align:center;white-space:pre-line;">
<h:outputText value="#{row.gestion.matricule.substring(10)}" />
</p:column>
<p:column headerText="Statut" style="width:150px;text-align:left;white-space:pre-line;" sortBy="#{row.statut}">
<h:outputText value="#{row.statut}" />
</p:column>
<p:columns value="#{consultationView.columns}" var="column" columnIndexVar="colIndex"
visible="#{column.property.matches('Z06|Z07|Z09')}" >
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{row.getRubValue(column.property)}" />
</p:columns>
</p:dataTable>`
Sorry Long post xs
I try to export some data loded from database.
With the code below, the exported file shows empty values in all columns althought my variable marchebean.selectedmarche.marchetraveau contains values.
Is there anything wrong in my code ?
I'm using Primefaces 4.0 and this is my xhtml page
<h:form id="form">
<p:tabView>
<p:tab title="Visualiser ">
<p:panel>
<h:commandLink >
<p:commandButton value="exporter" />
<p:dataExporter type="xls" target="crs" fileName="prixde" pageOnly="true" />
</h:commandLink>
<p:dataTable id="crs" var="marche" value="#{marchebean.selectedmarche.marchetraveau}" >
<f:facet name="header">
Tbaleau des travaux
</f:facet>
<f:facet name="footer">
<h3> Total HTVA = #{marchebean.calculdetotaltravhtva()}</h3>
<h3> Total TTC = #{marchebean.calculdetotaltravttc()} </h3>
</f:facet>
<p:column headerText="article" width="10%" >
<h:outputText value="#{marche.traveaux.article}"/>
</p:column>
<p:column headerText="Désignation des traveaux" width="40%" >
<h:outputText value="#{marche.traveaux.designation}"/>
<h:outputText value="#{marche.traveaux.paragraph}"/>
</p:column>
<p:column headerText="Unité">
<h:outputText value="#{marche.traveaux.unite}"/>
</p:column>
<p:column headerText="PUHTVA">
<h:outputText value="#{marche.prixunitaire}"/>
</p:column>
<p:column headerText="PUTTC">
<h:outputText value="#{marchebean.calcultva(marche.prixunitaire)}" />
</p:column>
<p:column headerText="Qtt">
<h:outputText value="#{marche.quantite}"/>
</p:column>
<p:column headerText="MHTVA">
<h:outputText value="#{marchebean.calculmonthtva(marche.prixunitaire ,marche.quantite)}" />
</p:column>
<p:column headerText="MTTC">
<h:outputText value="#{marchebean.calculmontttc(marche.prixunitaire ,marche.quantite)}" />
</p:column>
</p:dataTable>
</p:panel>
</p:tab>
</p:tabView>
</h:form>
we need to provide the
<f:facet name="header>
<h:outputText value="aricle"/>
</f:facet>
then exporter will add the headers to your exported document.
<p:column headerText="article" width="10%" >
<f:facet name="header">
<h:outputText value="article" />
</f:facet>
<h:outputText value="#{car.traveaux.article}"/>
</p:column>
This works for me. Maybe it needs validation and that's why it's empty at the end. Adding immediate="true" skips the validation.
<h:form id="confColaForm" .....>
<p:dataTable id="tablacolas" ... >
<f:facet name="header">
<h:commandLink id="exportar" update=":confColaForm:tablacolas" style="align:right;" immediate="true" >
<h:graphicImage library="images" name="iconexcel.png" style="width:30px;height:30px; "
title="Exportar" />
<p:dataExporter type="xls" target="tablacolas" fileName="ConfiguracionColas" />
</h:commandLink>
</f:facet>
...(columns here)
</p:dataTable/>
</h:form>
possible reason may be the "managedbean scope"...
1)change scope to "view"
2)serialize managedbean
this worked for me
I am using PrimeFaces 5 and using dataexporter to export .xls and pdf file. When i click on export, nothing seems to be happening. Below is my code:
<h:body>
<h:form id="formReport">
<ui:include src="menu.xhtml"></ui:include>
<p:dataTable id="ngoReporttbl" var="obj" styleClass="datatable"
value="#{ngoReportController.ngoReportList}" >
<f:facet name="header">
List of Cars
<p:commandButton id="toggler" type="button" value="columns" style="float:right" icon="ui-icon-calculator"></p:commandButton>
<p:columnToggler datasource="ngoReporttbl" trigger="toggler"></p:columnToggler>
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="NGO Id"></h:outputText>
</f:facet>
<h:outputText value="#{obj.ngoId}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="NGO Name Org"></h:outputText>
</f:facet>
<h:outputText value="#{obj.ngoNameOrg}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Environment"></h:outputText>
</f:facet>
<h:outputText value="#{obj.environment}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Livelihood"></h:outputText>
</f:facet>
<h:outputText value="#{obj.livelihood}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Country"></h:outputText>
</f:facet>
<h:outputText value="#{obj.country}"></h:outputText>
</p:column>
</p:dataTable>
<h:commandLink style="float:right">
<p:graphicImage value="../images/pdf.png" width="45"></p:graphicImage>
<p:dataExporter type="pdf" target="ngoReporttbl" fileName="ngoReport" pageOnly="true"></p:dataExporter>
</h:commandLink>
<h:commandLink style="float:right">
<p:graphicImage value="../images/csv.png" width="45"></p:graphicImage>
<p:dataExporter type="xls" target="ngoReporttbl" fileName="ngoReport" pageOnly="true"></p:dataExporter>
</h:commandLink>
<ui:include src="footer.xhtml"></ui:include>
</h:form>
</h:body>
Both the dataTable and the Export command are within one form. It is similar to the example given on primefaces.org site. But, I'm unable to export data to pdf, cvs.
For XLS, you don't need anything extra. For PDF, you need POI. Primefaces only works with 2.1.7 due to licensing issues. And your commandButton / commandLink need to be ajax="false". Good luck.
I'm trying to include the paginator on my datatable but it's not working, i have the table and the paginator shows but it's not working, always int page 1 !!
this is my code :
![datatable paginator not working ][1]
<h:form id="form">
<p:outputPanel id="users">
<p:dataTable id="usersTable" value="#{personBean.allPersons}" paginator="true" rows="4" var="person" >
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<p:commandLink action="#{personBean.editPerson}">
<h:outputText value="#{person.name}" />
<f:setPropertyActionListener target="#{personBean.person}"
value="#{person}" />
</p:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Age" />
</f:facet>
<p:commandLink action="#{personBean.editPerson}">
<h:outputText value="#{person.age}" />
<f:setPropertyActionListener target="#{personBean.person}"
value="#{person}" />
</p:commandLink>
</p:column>
</p:dataTable>
</p:outputPanel>
<p:commandButton value="Create New User"
action="#{personBean.newPerson}" />
</h:form>
always i have the same table, i can't move to 2
I have problem with datatable using Primefaces 2.2.1 and JSF 2.0.
I have used filtering and paging in the datatable. When I try to filter the selected data is displayed and when i remove the filter the entire data is displayed. But after this when i try to use paging then suddendly all the rows becomes blank(empty)
See screenshot below
Any suggestions. Please help.
.xhtml file
<p:dataTable var="user" value="#{userManagedBean.searchUsersResults}"
selection="#{userManagedBean.selectedUser}" selectionMode="single"
dynamic="true"
onRowSelectUpdate="userUpdateForm"
onRowUnselectUpdate="userUpdateForm"
rowSelectListener="#{userManagedBean.onUserSelect}"
rowUnselectListener="#{userManagedBean.onUserUnselect}"
paginator="true" rows="10" style="width: 70% ">
<p:column sortBy="#{user.userId}" filterBy="#{user.userId}" >
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{user.userId}" />
</p:column>
<p:column sortBy="#{user.username}" filterBy="#{user.username}">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{user.username}" />
</p:column>
<p:column sortBy="#{user.emailId}" filterBy="#{user.emailId}">
<f:facet name="header">
<h:outputText value="Email" />
</f:facet>
<h:outputText value="#{user.emailId}" />
</p:column>
<p:column sortBy="#{user.dob}" filterBy="#{user.dob}">
<f:facet name="header">
<h:outputText value="DOB" />
</f:facet>
<h:outputText value="#{user.dob}" >
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
</p:column>
</p:dataTable>
<p:panel id="userDetailsPanelId" header="Users Details" style="width:60%;">
<h:panelGrid columns="2" cellpadding="2" id="userUpdateForm" border="0" >
<h:outputLabel for="#{userManagedBean.selectedUser.userId}" value="UserId"/>
<h:inputText value="#{userManagedBean.selectedUser.userId}" style="width: 100%;" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.username}" value="Username"/>
<h:inputText value="#{userManagedBean.selectedUser.username}" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.emailId}" value="EmailId"/>
<h:inputText value="#{userManagedBean.selectedUser.emailId}" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.gender}" value="Gender"/>
<h:inputText value="#{userManagedBean.selectedUser.gender}" readonly="true"></h:inputText>
<h:outputLabel for="#{userManagedBean.selectedUser.dob}" value="DOB"/>
<h:inputText value="#{userManagedBean.selectedUser.dob}" readonly="true">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:inputText>
</h:panelGrid>
</p:panel>
</h:form>
</center>
I encountered the same problem and eventually discovered it was caused by my value object (in this case your user object) not implementing Serializable.
I'm pretty sure that this known issue has been resolved in both the 2.2.RC and the 2.2 final. I suggest updating your jar file.