In this article, we show you how to create a custom converter in JSF 2.0.
Free online PDF converter to convert your documents on the go. Upload your PDF, PS, EPS, XPS and text and get the new file type in seconds. Free online PDF converter from Coolutils is safe, we require no email address or other personal data. Conversion of jsf file format to pdf file format beta Search for jsf to pdf converter or software able to handle these file types. Possible software with support for converting of jsf files to pdf file format. Try Soda PDF's FREE online PDF converter: convert PDF to Word, convert PDF to Excel, convert PDF to PowerPoint, convert PDF to JPG, convert PDF to HTML files. Convert files like images, video, documents, audio and more to other formats with this free and fast online converter. Convert a PDF file to DOC or the Microsoft. Convert documents and images to PDF with this free online PDF converter. You can even take a screenshot of a website by providing us the URL and convert HTML to PDF. Upload your document and convert to PDF instantly. Optionally just enter a URL and we will convert the file we find there.
Jsf File Converter
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.
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.