Datatable issues when presenting dynamic columns - primefaces

I've got a NULLPointerException.
I have iplemented an object called Workhours, which has list of Hours and a workday (enum value).
Now, I have a list
I would like to present it in a datatable with the workday (enum) name as a row, and the hours as columns. Now, this is what I tried:
<p:dataTable id="dtWorkHours" var="workhour" value="#{uploadImagesPage.lwh}" >
<p:column>
<f:facet name="header">
<h:outputText value="Days"></h:outputText>
</f:facet>
<h:outputText value="#{workhour.workday}"></h:outputText>
</p:column>
<p:columns value="#{workhour.luh}" var="columnUntilHours" columnIndexVar="index">
<f:facet name="header">
#{columnUntilHours.untilhours}
</f:facet>
<h:selectBooleanCheckbox value="#{columnUntilHours.checked}" >
</h:selectBooleanCheckbox>
</p:columns>
</p:dataTable>
I checked initialization of WorkHours object and it seems everythings's in place. Is there any reason why I p:columns doesn't work (and when I put it out, the workday presentation as row works)?
Thanks in Advance !

I do not believe it is possible to mix dynamic and static columns within a single Primefaces dataTable. You must choose one method or the other.
If you wish to show the workday column within this then perhaps you can create create a viewable composite entity type that combines properties of both workday and the row entities into a single type. Workday can be just another object that always exist in your dynamic column collection.

Related

Expand a specific row of a p:dataTable

I have a screen where I have a list of items and an expansion button left. In the filter if the user enter with a specific information it will bring the same entire list BUT I need to expand the specific row.
<p:rowExpansion>
<p:dataTable var="inventoryPartsItems"
value="#{partnerInventory.getInventoryItems(inventoryPart)}"
emptyMessage="#{msgs.common_no_registries}" id="tableItems">
<p:column style="width:16px">
<p:rowToggler
rendered="#{inventoryPartsItems.sapOperation != null}" />
</p:column>

Primefaces dataTable populate (search) doesn't work well after filtering

I have a Primefaces dataTable like this in a <h:form> block:
<p:dataTable id="basicDT" var="partyDB" value="#{mbRechercheAbonne.listPartyDB}"
paginator="true"
emptyMessage="Aucun abonné ne correspond aux critères"
paginatorPosition="bottom"
paginatorAlwaysVisible="false"
rows="25"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25,50,100"
currentPageReportTemplate="{startRecord} - {endRecord} sur {totalRecords} résultats"
filteredValue="#{mbRechercheAbonne.filteredListPartyDB}">
and a search button that populates the dataTable using a #ViewScoped bean that updates the value of listPartyDB when rechercheAbonne() is called:
<p:commandButton value="Rechercher" update="display :consultform:basicDT" icon="ui-icon-check"
actionListener="#{mbRechercheAbonne.rechercheAbonne()}" onstart="startRecherche()" oncomplete="stopRecherche()"/>
Searching multiple times works, the dataTable's content changes like expected.
However, when using filtering and then removing the filter (i.e. adding a letter in a filter field above a column and then removing that letter), the search no longer works. I found that the search does actually work, but I need to apply a filter again (and remove it to have the unfiltered list) to see the result of the new search.
Explaining with pictures :
Searching for "test":
Searching for "abc" right after, works as intended:
Searching for test again, filtering one column, works as intended:
Removing the filter (going back to pic 1), and then searching for "abc". Does not work:
Applying a filter again does it on the "abc" search that wasn't showing originally - removing the filter shows what the last search should have shown.
Thanks for your help.

Primefaces dataTable iterate list inside list by index

In my JSF example I am getting a list which contains two lists:
One for result returned from DB and another containing list of column header from DB.
In the first list(containing result) has row data per index.
e.g. **
transaction.transactionsList[0][1]
contain one row data in below code snippet:
<p:dataTable value="#{transaction.transactionsList[0]}" var="tran">
<p:columns value="#{transaction.transactionsList[1]}" var="column"
sortBy="#{tran[column.property]}">
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{tran[column.property]}" />
</p:columns>
</p:dataTable>
Please advise how to iterate based on length of list containing data and based on index over nested list, like:
transaction.transactionsList[0][i]

primefaces:datatable: custom filter: "contains" instead of "beginning"

By default, primeface filter dataTable's rows, by finding rows that columns begins with the string entered in the search area.
How do I filter the DataTable rows that the column contains (not begins with) the string entered in the search area?
You can do this using filterMatchMode attribute on p:column of the dataTable. A very good example can be found on PrimeFaces showcase.
So if we take the above mentioned example, you could have roughly something like this:
<p:dataTable var="car" value="#{dtFilterView.cars}" widgetVar="carsTable"
filteredValue="#{dtFilterView.filteredCars}">
<p:column filterBy="#{car.id}" headerText="Id" footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
The attribute filterMatchMode accepts values such as contains, endsWith, startsWith, exact...

primefaces dataexport from table with column content in ui:repeat

I have a master detail resultset that I present on a datatable.
The detail is fetched and rendered within to be combined into a single output string that remains in one column.
<p:column>
<f:facet name="header">BF Order Contents</f:facet>
<ui:repeat value="#{order.listOfOrderDetails}" var="orderitem" varStatus="orderitemstatus" >
<h:outputText value="#{orderitem.product.brand.name}-#{orderitem.product.name}#{orderitemstatus.last ? '':', '}" />
</ui:repeat>
</p:column>
On the datatable, that column displays as "Some Brand-Some Product, Other Brand-Other Product"
But when I export to EXCEL, I see:
com.sun.faces.facelets.component.UIRepeat#783622ba
in that column.
Does anyone have any idea about how I can overcome this (within xhtml only). I don't want to alter the backing bean to produce the detail string.
BTW: I'm on PF3.2, Mojarra 2.1.8, EL 2.2.1-b04, JDK1.7, Tomcat7
Thanks
It can be solved in the below manner.
Column having ui:repeat should not be made exportable i.e set exportable="false" attribute for p:column.
Add one more column to display the string property (write bussiness logic to convert list of string to a comma seperated string and set it the string property)
set the style as display:none; for the new column.
so during ui display, the previous column will display and during export the new column will be displayed showing comma seperated list.
I really don't think its possible , even with overriding the exporter class in the primefaces sources it will be way to complicated...
You probably better alter the backing bean
Also, you can add a star on a bit related an issue opened by me Feature request: Datatables custom filter function - filterFunction (like sortFunction for sort)
You can write a facelet function that does the iteration in Java and returns a string.. this will work just put it to outputText, or do 2 columns one put exportable false and the other make CSS display:none