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

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.

Related

Enable/Disable command button based on datatable errors

I am using PrimeFace 5.0.
I have a datatable with a editable date field.
Outside the data-table is a comman button, I want to enable/disable the command button based on the errors on the page.Here is the codes for teh common button.
<p:commandButton value="xxxx" id="xxxBtn" type="submit" partialSubmit="true" ajax="true" update="#form" disabled="#{not empty facesContext.messageList}"
actionListener="#{xxxBean.xxx}" styleClass="Win95 Fnone marAuto">
The command button is disabled when there are error messages on the page, on one or multiple rows in the data-table, but if I correct one of the rows error messages the button becomes enabled, even though there are errors existing on the other rows in the data-table.
change
{not empty facesContext.messageList}
to
{not empty facesContext.messageList?true:false}

pagination is invisible after selecting above rows limit

I am using <p:datatable/> with paginatorTemplate, everything works fine with the datatable and template. I have an apply commandbutton which on click renders this datatable. The problem is that when i select more than 50 which is the current rows limit and click on apply my pagination is gone. I works fine if i select 50 or below, the pagination shows. Please find my code snippet below:
<p:dataTable id="claimDataTableId"
value="#{inventoryBean.caseInventoryClaimLineDataModel}"
var="entityData" rowKey="#{entityData.getRowKeyID()}"
rowIndexVar="rowIndexVar" widgetVar="dataTableWV"
paginatorAlwaysVisible="false" expandedRow="#{entityData.claimSelectedRow}" scrollable="false" sortBy="#{entityData.getCaseClaimLineId()}"
selection="#{inventoryBean.selectedClaimProfList}"
styleClass="#{tableStyleClass} #{enablePrimefacesPagination == null or !enablePrimefacesPagination or !signIn.currentDevice.normal? 'ux-dt-display' : ''}"
resizableColumns="true" emptyMessage="No Claims found"
rows="50"
paginator="true"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25,50,100,150,200"
editable="false" lazy="false">
=========================================
<a4j:commandButton
value="Apply"
id="applyBtnId"
styleClass="ux-btn" style="padding-top:0p"
render="ClTxtArea claimDataTableId faciltyClaimDataTableId
secNavTab:processedErrorMessagePanelGrid secNavTab:validationErrorMainPanelGrid">
Please suggest where i am going wrong.
Thanks
You most likely mean that you have only 50 rows in your dataset and that if you select to display a maximum of '200' rows, then the paginator disappears. Well, that is exactly as you tell it to do by adding
paginatorAlwaysVisible="false"
If you remove this (or set it to true, the default), then the paginator is always visible. This is all mentioned in the docs. Please use them... learn how to create [mcve] and you'd have found this within 10 minutes.

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...

JSF how to split forms

is it possible to "split" a form?
e.g. i have two forms which would collide (one row of a table needs to stay in form 1, the other in form 2 and so on)
so i need a technique to make this possible like in HTML5 (form="formid")
all black fields must be the same form (content)
and all red fields are also one form together (actions for submit)
I need to be able to access both of them individually, they are just positined like the picture above. unfortunately I cannot make a form of a specific shape which includes some components and others not.
Just use
<ui:repeat>
<h:form>
...
</h:form>
</ui:repeat>
instead of
<h:form>
<ui:repeat>
...
</ui:repeat>
</h:form>

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