How to export datatable in HTML format? - jsf

I am using primefaces 5.0 jar files. I searched on google and found that primefaces datatable is not supported to export html format. its support only csv, xls, pdf and xml format. but i want to achieve this functionality so any one know how to achieve this functionality.
Is there any alternative way to export datatable in html format?

It is not to difficult to add an additional format to the PrimeFaces exporter.
Just override two classes in PrimeFaces (you can put the overridden classes in your own application with the same name and package):
org.primefaces.component.export.ExporterType.java
org.primefaces.component.export.ExporterFactory.java
In the first you add "HTML" and in the second you add an additional case in the switch:
case HTML:
exporter = new HTMLExporter();
break;
This HTMLExporter does not exist, and you need to use one of the existing exporters as an example to create your own HTMLExporter (if you put it in a different package than org.primefaces.component.export, you might need to also add an import statement in the ExporterFactory, but that is hopefully obvious)

Related

Primefaces editor generates span elements

I use primefaces editor within a project (http://www.primefaces.org/showcase/ui/input/editor.xhtml). My problem is that it always generates SPAN elements.
E.g. test is exported as
<span style="font-weight: bold;">test</span>
Instead of this, I need to generate markup (and so for the other functions) liek this:
<b>test</b>
Any idea?
(it is not my personal wish but a need to be compatible with a legacy API)
Instead of <p:editor> use <pe:ckEditor> primefaces extension, and there are various options available for this choose according to your requirement primefaces editor will always generate span for text.

Allow only specific tag in <h:outputText> [duplicate]

Is there any HTML sanitizer or cleanup methods available in any JSF utilities kit or libraries like PrimeFaces/OmniFaces?
I need to sanitize HTML input by user via p:editor and display safe HTML output using escape="true", following the stackexchange style. Before displaying the HTML I'm thinking to store sanitized input data to the database, so that it is ready to safe use with escape="true" and XSS is not a danger.
In order to achieve that, you basically need a standalone HTML parser. HTML parsing is rather complex and the task and responsibility of that is beyond the scope of JSF, PrimeFaces and OmniFaces. You're supposed to just grab one of the many existing HTML parsing libraries.
An example is Jsoup, it has even a separate method for the particular purpose of sanitizing HTML against a Safelist: Jsoup#clean(). For example, if you want to allow some basic HTML without images, use Safelist.basic():
String sanitizedHtml = Jsoup.clean(rawHtml, Safelist.basic());
A completely different alternative is to use a specific text formatting syntax, such as Markdown (which is also used here). Basically all of those parsers also sanitize HTML under the covers. An example is CommonMark. Perhaps this is what you actually meant when you said "stackexchange style".
As to saving in DB, you'd better save both the raw and parsed forms in 2 separate text columns. The raw form should be redisplayed during editing. The parsed form should be updated in background when the raw form has been edited. During display, obviously only show the parsed form with escape="false".
See also:
Markdown or HTML

Embed HTML in JSF [duplicate]

Is there any HTML sanitizer or cleanup methods available in any JSF utilities kit or libraries like PrimeFaces/OmniFaces?
I need to sanitize HTML input by user via p:editor and display safe HTML output using escape="true", following the stackexchange style. Before displaying the HTML I'm thinking to store sanitized input data to the database, so that it is ready to safe use with escape="true" and XSS is not a danger.
In order to achieve that, you basically need a standalone HTML parser. HTML parsing is rather complex and the task and responsibility of that is beyond the scope of JSF, PrimeFaces and OmniFaces. You're supposed to just grab one of the many existing HTML parsing libraries.
An example is Jsoup, it has even a separate method for the particular purpose of sanitizing HTML against a Safelist: Jsoup#clean(). For example, if you want to allow some basic HTML without images, use Safelist.basic():
String sanitizedHtml = Jsoup.clean(rawHtml, Safelist.basic());
A completely different alternative is to use a specific text formatting syntax, such as Markdown (which is also used here). Basically all of those parsers also sanitize HTML under the covers. An example is CommonMark. Perhaps this is what you actually meant when you said "stackexchange style".
As to saving in DB, you'd better save both the raw and parsed forms in 2 separate text columns. The raw form should be redisplayed during editing. The parsed form should be updated in background when the raw form has been edited. During display, obviously only show the parsed form with escape="false".
See also:
Markdown or HTML

chosen jquery not show correctly

I use chosen 1.2.0 from nuget. My chosen.css file contains class like .chosen-container, .chosen-container. When i call my dropdownlist class using .chosen() function. Resulted css class will be chzn-container, chzn-container-multi. It causes display ugly. but functionality work. I have no error in browser console.
When i check another sites, both generated markup and chosen.css contains chzn-container, chzn-container-multi classes only.
Nuget adds only css. It is not add chosen.jquery.js. I don't know why.
The Nuget package named simply "chosen" does not, as the OP says, contain the .js.
You need to search for Harvest.Chosen. Hopefully this will help someone in the future.

How to export <table> content (which is inside a one <div >) into excel by JSP

I have developed a web application using JSP which creates a page with
several page elements and a with multiple records.
I wanted to export the content in that into an excel file.
I used the code
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename="
+ "excel.xls");
as described in this article http://www.quicklyjava.com/export-web-page-to-excel/
But it exports the whole page.
How can a export only the content in that particular table?
I cannot use the Apache POI library since i have to format(text colors,cell colors) the content in the JSP. And i need the same formatting in the excel file.
Can somebody help me with this? :)
Haven't found a way to export only a single table in a page.
But the intended task(create a excel sheet with formatted data) can be done by Apache POI HSSF library
Here are the links to learn how to & examples -
http://poi.apache.org/spreadsheet/how-to.html#user_api
http://poi.apache.org/spreadsheet/examples.html

Resources