EL on DataTable Footer not showing - jsf-2

I'm working with a DataTable, and I'm having some trouble displaying a value from an EL in the footer. I have made a simplified version of my xhtml that still reproduces the error.
If I do the p:dataTable like this it all works:
<p:dataTable value="#{myMB.items}" var="item">
<p:column headerText="Value" footerText="Value">
<h:outputText value="#{item.value}">
<f:convertNumber pattern="###,##0.00"/>
</h:outputText>
</p:column>
</p:dataTable>
I get this as a result:
The footer shows just fine. And then I try it with EL, changing the column definition like this:
<p:column headerText="Value" footerText="#{3 + 11}">
<h:outputText value="#{item.value}">
<f:convertNumber pattern="###,##0.00"/>
</h:outputText>
</p:column>
And it evaluates my expression, I get this as a result:
It shows the correct value 14 in the footer. But when I try to use a value from my model, it doesn't show. See the example:
Code:
<p:column headerText="Value" footerText="#{item.value}">
<h:outputText value="#{item.value}">
<f:convertNumber pattern="###,##0.00"/>
</h:outputText>
</p:column>
Output:
And I have tried to do the footer in different ways. Not a single attempt worked.
Is there a correct way to do this? In the showcase it seems to work just fine.
I am using PrimeFaces 3.3.1

The problem was lack of attention.
I failed to realize that I have multiple column values for a single footer. And since JSF can't decide on a single value, it shows nothing.
Shortly after I posted this the answer came to me. I tried to define a single value on my ManagedBean to use as footer, and it work just fine.
Again, there's nothing wrong with JSF and/or PrimeFaces, it was just lack of logical thinking from my part.
It works on the showcase, because it shows subtables that actually do have a footer for each value.

Related

Remove sort indicators Primefaces DataTable

I have a Primefaces DataTable with sortable columns. Even though it implements single sort (with and without sortMode="single"), the sort indicators on other columns do not disappear when I sort by a new column. It's purely for aesthetics, but I would like to remove the indicator once another column is sorted. I'm new to jsf and inherited this project, so there may be something happening behind the scenes that I don't understand. Here is a snippet from the xhtml:
<p:dataTable id="searchResults"
value="#{searchController.searchResults}"
var="emr"
selection="#{searchController.selectedEmr}"
rowKey="#{emr.emrid}"
selectionMode="single" widgetVar="theTable"
scrollable="true"
resizableColumns="true"
stickyHeader="true"
rowIndexVar="rowIndex"
sortBy="#{emr.emrid}"
styleClass="stdSearchResult">
<f:facet name="header">
Search Results
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Emr ID" sortBy="#{emr.emrid}" styleClass="wrap">
<h:outputText value="#{emr.emrid}" title="emrId"/>
</p:column>
Table:
Seems like an obvious name now, but removing stickyHeader="true" accomplished the desired functionality. Thank you for the assistance.

p:dataExporter does not keep the sorting of p:dataTable

The problem can be reproduced in PrimeFaces showcase:
http://www.primefaces.org/showcase/ui/data/dataexporter/basic.xhtml
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage name="/demo/images/excel.png" width="24"/>
<p:dataExporter type="xls" target="tbl" fileName="cars" />
</h:commandLink>
</f:facet>
I have no idea from where the export gets the sorting that it is using.
Is there any way to make p:dataExporter to keep the same order as in p:dataTable?
Edit: My client noticed that if you click a column to sort the datatable then export keeps the sorting. That's good but how to keep the initial sorting?

show data in ascending or descending manner

We are using JSF and primefaces to develop application, i have a scenario where it will show data in the table and on click on any column header the data should get sorted either ascending/descending. BUt problem is the sort functionality is not working nor throwing any kind of errors to debug. Below is the code i have written:
Please let me know do i need to include any other attributes to make sorting work.
Thanks.
Change your columns like this
<p:column id="NumberCol" sortBy="#{OrderInfo.orderNumber}" headerText="Order Number" >
<h:outputText value="#{OrderInfo.orderNumber}" />
</p:column>
<p:column id="NumberCol" sortBy="#{OrderInfo.Number}" headerText="Number" >
<h:outputText value="#{OrderInfo.Number}" />
</p:column>
This should work.
Hope this helps

filterBy (primefaces 3.2) doesn't work with date

am usign jsf 2.0 + primefaces 3.2. i have a problem with filterBy when the data is a date but it works with other types of data.
<p:column sortBy="#{item.dateNaissance}" filterBy="#{item.dateNaissance}">
<f:facet name="header">
<h:outputText value="#{bundle.ListEtudiantTitle_dateNaissance}"/>
</f:facet>
<h:outputText value="#{item.dateNaissance}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
default filtering doesn't work for date field, though you can use advanced filtering option and provide a filter server side method which does the filtering from the data set for you.
Basically you will specify your metho on key up event and filter record as per your need, default assumes everything to be String.

JSF 2, Primesfaces: Update cell on selectOneMenu selection in Incell Editing

I'm using Primesfaces' Incell editing in a p:dataTable.
When choosing a new id in the selectOneMenu, I'd like to update the 'name' field in the same row without having to wait until the user presses the ok check mark for the name field to be updated. Objects' name attribute is updated in bean.idEdited(object).
I was hoping I could just use f:ajax render="name" to update the other field like this:
<h:form>
<p:dataTable var="object" value="#{bean.objects}"
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{bean.objectId}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{bean.objectId}">
<f:selectItems value="#{bean.objectIds}" />
<f:ajax listener="#{bean.idEdited(object)}"
render="name" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<h:outputText id="name" value="#{object.name}" />
</p:column>
</p:dataTable>
</h:form>
When I try render="name" I get this:
SEVERE: Error Rendering View[/logicalAddress.xhtml]
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2867)
...
Using
Primesfaces 2.2.1
Netbeans 7.0.1
JSF Bundled with Netbeans
Ideas, other ways or salvation?
edit: p:ajax renders the same result.
This is happening because when you are calling ajax to render the page, that page is already rendered.
TIP: If you use primefaces you could also use primefaces components where this is possible. Also upgrade to Primefaces 3.0.M4 for a better implementation. You also have a primefaces selectOneMenu component, and you can use primefaces ajax (p:ajax event="onchange") with update attribute (update the entire form)
updating the entire form with p:ajax certainly updates the name field but the row will no longer be in edit mode after this. If the user wants to edit the other cell in the same row, he has to explicitly go into edit mode

Resources