Reputation: 63
I have a Primefaces dataTable where one column is having three output texts and one command button with tooltip. The button appears with output labels as
This is for export label. This is for text.org.primefaces.component.commandbutton.CommandButton@3f60d3f9
How can I not include/print this command button with tooltip to export the dataTable to excel?
I can't move the command button to new column for business case.
Upvotes: 3
Views: 3935
Reputation: 12335
In PrimeFaces you can override the exported content of a column by using the exportFunction
attribute (which is in the documentation). If you'd read this in the documentation, you'd easily have found https://forum.primefaces.org/viewtopic.php?t=50284 by using google. In it, an example is given of how to override the 'exported value' of a column:
XHTML:
<p:column exportFunction="#{testView.exportBrand}">
<f:facet name="header">
<h:outputText value="Brand" />
</f:facet>
<h:outputText value="#{car.brand}" />
</p:column>
Java:
public String exportBrand(UIColumn column) {
String value = "";
for(UIComponent child: column.getChildren()) {
if(child instanceof ValueHolder) {
value = ComponentUtils.getValueToRender(FacesContext.getCurrentInstance(), child);
}
}
return value + "_TEST";
}
Just extend this and in the for loop only export things you want to export.
Upvotes: 3
Reputation: 1312
As an addition to @Kukeltje's answer I like to mention that you can also specify your own method parameter (instead of using UIColumn
):
Facelet:
<p:column exportFunction="#{testView.exportBrand(car)}">
<f:facet name="header">
<h:outputText value="Brand" />
</f:facet>
<h:outputText value="#{car.brand}" />
</p:column>
Backing bean:
public String exportBrand(Car car) {
if (car == null) {
return null;
}
return car.getBrand();
}
Upvotes: 10