O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The JSP Tag Handler Class

As usual, we also need a custom action tag handler class for the component/renderer combination:

package com.mycompany.jsf.taglib;

import javax.faces.webapp.UIComponentTag;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import com.mycompany.jsf.component.UITree;

public class TreeTag extends UIComponentTag {
    private String value;
    private String var;
    private String varNodeToggler;

    public void setValue(String value) {
        this.value = value;
    }

    public void setVar(String var) {
        this.var = var;
    }

    public void setVarNodeToggler(String varNodeToggler) {
        this.varNodeToggler = varNodeToggler;
    }

    public String getComponentType( ) {
        return "com.mycompany.Tree";
    }

    public String getRendererType( ) {
        return "com.mycompany.Tree";
    }

    protected void setProperties(UIComponent component) {
        super.setProperties(component);

        FacesContext context = getFacesContext( );
        if (value != null) {
            ValueBinding vb = 
                context.getApplication( ).createValueBinding(value);
            component.setValueBinding("value", vb);
        }
                
        if (var != null) {
            ((UITree) component).setVar(var);
        }
                
        if (varNodeToggler != null) {
            ((UITree) component).setVarNodeToggler(varNodeToggler);
        }
    }
}

The com.mycompany.jsf.taglib.TreeTag follows the same pattern as all other component tag handlers, with setter methods for all action attributes, getComponentType() and getRendererType() methods returning the appropriate values, and a setProperties() method that sets the component ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required