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

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