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 ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.