My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians


sâmbătă, 14 februarie 2015

JSF 2.2 - Writing a custom component handler skeleton

In order to write and configure a ComponentHandler, you have to accomplish several steps:

·         First, you need a component (built-in, or custom). Let's suppose that we have the below dummy component:

package custom.componenthandler;

import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;

public class DummyComponent extends UIComponentBase {

 public static final String COMPONENT_FAMILY = "dummy.components";
 public static final String COMPONENT_TYPE = "dummy";

 public String getFamily() {

·         Further, extend the ComponentHandler class and override the desired methods. Per example, a dummy component handler skeleton is listed below - it simply delegates tasks to the superclass:

package custom.componenthandler;

import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.view.facelets.ComponentConfig;
import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.FaceletContext;

public class CustomComponentHandler extends ComponentHandler {

 private static final Logger logger =

 public CustomComponentHandler(ComponentConfig config) {

 //only in JSF 2.2
 public UIComponent createComponent(FaceletContext ctx) {"Inside 'createComponent' method");
  return super.createComponent(ctx);

 public void onComponentCreated(FaceletContext ctx, UIComponent c, UIComponent parent) {"Inside 'onComponentCreated' method");
  super.onComponentCreated(ctx, c, parent);

 public void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent) {"Inside 'onComponentPopulated' method");
  super.onComponentPopulated(ctx, c, parent);

·         Next, you need to write a *.taglib.xml file to link the handler class with the component. Per example, dummy.taglib.xml from below:

<?xml version="1.0" encoding="UTF-8"?>


   <description>Component id</description>
  <!-- ... -->     


·         Finally, configure the *taglib.xml file in web.xml file. Per example:

Done! The complete code is available on GitHub.

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors