JSF 2.2: HTML 5 Support

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.

HTML5-App

Pass-through attributes

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

 

Namespace

[code language=”xml”]


JSF 2.2 HTML5 Support







[/code]

 

TagHandler

[code language=”xml”]


JSF 2.2 HTML5 Support









[/code]

[code language=”xml”]


JSF 2.2 HTML5 Support









[/code]

[code language=”java”]
private Map html5Attributes = new HashMap();

public MyBean(){
html5Attributes.put(“autofocus”, “true”);
html5Attributes.put(“placeholder”, “Enter text”);
}
[/code]

 

Programmatic

[code language=”java”]
HtmlInputText myInputText = new HtmlInputText();
Map passThrough = myInputText.getPassThroughAttributes();
passThrough.put(“placeholder”, “Enter text”);
[/code]

 

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.

[code language=”xml”]


HTML(5) Friendly Markup in JSF 2.2




[/code]

 

Conclusion

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.

No Comments

Post a Comment

Comment
Name
Email
Website