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

Twitter

miercuri, 28 ianuarie 2015

JSF 2.2 - Creating a Custom TagHandlerDelegate Skeleton

In order to write and configure a TagHandlerDelegate, you have to accomplish three steps:

·         extract the TagHandlerDelegate and override its methods

public class CustomTagHandlerDelegate extends TagHandlerDelegate {

 private TagHandlerDelegate tagHandlerDelegate;

 public CustomTagHandlerDelegate() {
 }

 public CustomTagHandlerDelegate(TagHandlerDelegate tagHandlerDelegate) {
  this.tagHandlerDelegate = tagHandlerDelegate;
 }

 @Override
 public MetaRuleset createMetaRuleset(Class type) {
  return tagHandlerDelegate.createMetaRuleset(type);
 }

 @Override
 public void apply(FaceletContext ctx, UIComponent comp) throws IOException {
  tagHandlerDelegate.apply(ctx, comp);
 }
}

·         Extend the TagHandlerDelegateFactory and point your TagHandlerDelegate

public class CustomTagHandlerDelegateFactory extends TagHandlerDelegateFactory {
  
    private TagHandlerDelegateFactory tagHandlerDelegateFactory;

    public CustomTagHandlerDelegateFactory() {
    }

    public CustomTagHandlerDelegateFactory(TagHandlerDelegateFactory tagHandlerDelegateFactory) {
        this.tagHandlerDelegateFactory = tagHandlerDelegateFactory;
    }

    @Override
    public TagHandlerDelegate createComponentHandlerDelegate(ComponentHandler owner) {       
        return new CustomTagHandlerDelegate(tagHandlerDelegateFactory.createComponentHandlerDelegate(owner));
    }

    @Override
    public TagHandlerDelegate createValidatorHandlerDelegate(ValidatorHandler owner) {      
        return tagHandlerDelegateFactory.createValidatorHandlerDelegate(owner);
    }

    @Override
    public TagHandlerDelegate createConverterHandlerDelegate(ConverterHandler owner) {     
        return tagHandlerDelegateFactory.createConverterHandlerDelegate(owner);
    }

    @Override
    public TagHandlerDelegate createBehaviorHandlerDelegate(BehaviorHandler owner) {      
        return tagHandlerDelegateFactory.createBehaviorHandlerDelegate(owner);
    }
}

·         configure the your custom TagHandlerDelegateFactory in faces-config.xml

<factory>
 <tag-handler-delegate-factory>
  your_custom_taghandlerdelegatefactory_package.CustomTagHandlerDelegateFactory
 </tag-handler-delegate-factory>
</factory>


Now, most probably, you will go in the apply() method and "play" with the component tree, during its construction.

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors