The TabbedRenderer Class

Let’s look at the custom renderer for the panel that contains all the tabs first. It’s a class called com.mycompany.renderer.TabbedRenderer:

package com.mycompany.jsf.renderer; import com.mycompany.jsf.component.UITabLabel; import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.component.UIComponent; import javax.faces.component.UIViewRoot; import javax.faces.render.Renderer; public class TabbedRenderer extends Renderer { public boolean getRendersChildren( ) { return true; } public void decode(FacesContext context, UIComponent component) { Iterator i = component.getChildren( ).iterator( ); while (i.hasNext( )) { UIComponent child = (UIComponent) i.next( ); if (!child.isRendered( )) { UITabLabel tabLabel = (UITabLabel) child.getFacet("label"); if (tabLabel != null) { tabLabel.processDecodes(context); } } } } public void encodeBegin(FacesContext context, UIComponent component) throws IOException { if (!component.isRendered( )) { return; } int selected = 0; List children = component.getChildren( ); boolean pickedSelected = false; for (int i = 0; i < children.size( ); i++) { UIComponent child = (UIComponent) children.get(i); if (child.isRendered( ) && !pickedSelected) { selected = i; pickedSelected = true; } else { child.setRendered(false); } } String labelAreaClass = (String) component.getAttributes( ).get("labelAreaClass"); String ...

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.