HTML 5 is the fifth version of the HTML markup Standard. HTML5 arose as a result of ideas and needs such as developing new generation web applications, providing standardization between browsers and using a single codebase. Back end and UI developers can benefit from a single codebase with HTML5.
JavaServer Faces version 2.2 offers an easy way for including new attributes of HTML 5 to JSF components and provides HTML(5) friendly markup.
In order to ensure the higher level of flexibility, the logic of client-specific rendering must be avoided in JavaServer Faces component classes. Elements specific to the client or markup are defined in renderer classes. Renderer classes are responsible from encapsulation of the content that is client device-specific and then rendering to the client. For this reason, JSF does not support the new attributes of HTML5 automatically. In order to include HTML5 attributes to JSF components before JSF 2.2, writing custom render kits was an obligation.
JSF 2.2 introduced pass-through attributions to solve this problem. These attributes are going to be processed in the run time and at the client-side. They enable to use a differing collection as well as using the current attribute collection of component.
JSF 2.2 offers 4 ways to set in pass-through attributes:
- By a name-spaced attribute on component tag
- By f:passThroughAttribute TagHandler (a single attribute)
- By f:passThroughAttributes TagHandler (more than one attribute)
- By Programmatic way
html5Attributes.put(“placeholder”, “Enter text”);
HtmlInputText myInputText = new HtmlInputText();
Map passThrough = myInputText.getPassThroughAttributes();
passThrough.put(“placeholder”, “Enter text”);
Write pure HTML
HTML support that comes with JSF 2.2 is not limited with including HTML5 attributes to JSF components easily. Similar to pass-through attribute, the new version offers a possibility to use pure HTML components as JSF components (binding components to managed beans, associate a convertor with component etc.) through a name-spaced attribute on component tag, and then to provide an interaction with server.
With version 2.2, JavaServer Faces introduced an universal approach about including of HTML(5) attributes to JSF components and responded to one of the main criticisms toward itself by providing HTML(5) friendly markup.