Complete list of supported conversions
Jsf To Pdf Converter Online
|
|
|
|
|
|
|
|
In this article, we show you how to create a custom converter in JSF 2.0.
In Microsoft Windows 10, Microsoft has introduced a new feature call Print To PDF. It is an inbuilt pre-installed printer in Windows 10 that you can be used. This free online PDF converter converts images (JPG, TIFF, etc.), ebook files (ePub, MOBI, FB2, CBR, CBZ), documents (DOC, DOCX, PPT, XLS, ODT etc.) and other files of over 20 formats to PDF in just a single mouse click.
Steps
1. Create a converter class by implementing javax.faces.convert.Converter interface.
2. Override both getAsObject() and getAsString() methods.
3. Assign an unique converter ID with @FacesConverter annotation.
4. Link your custom converter class to JSF component via f:converter tag.
Custom converter example
A detail guide to create a JSF 2 custom converter name “URLConverter”, which is used to convert a String into an URL format (add HTTP protocol in front only :)) and store it into an Object.
1. Folder Structure
Folder structure of this example.
2. Converter class
Create a custom converter class by implementing javax.faces.convert.Converter interface.
Override following two methods :
1. getAsObject(), converts the given string value into an Object.
2. getAsString(), converts the given object into a String.
Assign an converter ID with @FacesConverter annotation.
See full custom converter source code :
URLConverter.java
In this custom converter class, it’s given a converter id as “com.mkyong.URLConverter“, and converts any given String (by adding a “http” in front) into “URLBookmark” object.
Convert Jsf File To Pdf
In addition, if URL validation is failed, return a FacesMessage object with declared error message.
URLBookmark.java
3. Managed Bean
A normal managed bean named “user”, nothing special here.
4. JSF Page
Link above custom converter to JSF component via “converterId” attribute in “f:converter” tag.
default.xhtml
result.xhtml
5. Demo
Enter a valid URL, without “http”.
Add a “http” in front of the valid URL and display it.
If an invalid URL is provided, return the declared error message.