10 Easy Steps for Creating Custom JSF Components

  1. Find out the standard HTML component that closely matches your required custom JSF component
  2. Write the component class that extends from the identified standard JSF component implementation. Override "getFamily()" method to return a "Family Name" for your custom component
  3. Write your custom validator class that performs required UI validations for your custom component. Your validator class implements "Validator" interface in JSF framework
  4. Include "addValidator(new YourValidator())" call in your component class.
  5. Write your Renderer class by extending "Renderer" class in JSF framework. Override "encode" (generate HTML for the component) and "decode" (interpret HTTP Request and set value to the component) methods based on your requirement.
  6. Create "faces-config.xml"
  7. Register your custom component class (created in step 2) in faces-config.xml with a unique "Component-Type" name.
  8. Register your custom Renderer class (created in step 4) in faces-config.xml with a unique "Renderer-Type" name.
  9. Create your custom Tag Handler class that extends "UIComponentTag" class provided by JSF Framework. Override "getComponentType()" and "getRendererType()" accessor methods. Make sure that the Type names returned by these two methods matches the names registered in faces-config.xml (Step 7 and Step 8)
  10. Create you Tag Library (TLD) for the custom Tag and associate Tag Handler (created in Step 9) class with the custom component tag.

0 comments: