Reputation: 425
I would like to have a current pager to wrap counts in spans (for testing purposes)
so I tried
<p:dataTable currentPageReportTemplate="Showing {startRecord} - {endRecord} of <span>{totalRecords}</span> items">
and found that tags are escaped. How to achieve this?
Upvotes: 1
Views: 747
Reputation: 97212
I took a look at the source code for PrimeFaces 5.0, and the least that I can say is that what you're trying to do is not going to be trivial.
In essence the behavior you witness is caused by the CurrentPageReportRenderer
. It writes out the current page report using this call to the ResponseWriter
:
writer.writeText(output, null);
The API documentation for this method shows why your markup is being escaped:
Write an object, after converting it to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered.
If you could somehow replace that call with the one below, your markup would be preserved:
writer.write(output);
It would be fairly trivial to extend the CurrentPageReportRenderer
and override the render
method, but wiring your custom renderer into PrimeFaces will prove to be a lot more challenging.
JSF does allow specifying custom renderers in the faces-config.xml
, but this happens at the component level. The default renderer used for the data table component is the DataTableRenderer
, which extends the DataRenderer
, which in turn does its magic with the CurrentPageReportRenderer
.
This means that you would have to provide a custom implementation of the DataTableRenderer
, in which you would have to override DataRenderer
's encodePaginatorMarkup
method where you plug in your custom CurrentPageReportRenderer
. Then you would have to set up your faces-config.xml
to tell JSF to use your renderer implementation instead of the one provided by PrimeFaces.
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.DataTableRenderer</renderer-type>
<renderer-class>org.example.MyDataTableRenderer</renderer-class>
</renderer>
All in all, it wouldn't be that hard to do, but the solution would be fairly fragile, and any significant changes in future versions of the aforementioned classes are liable to break your customization.
Upvotes: 2