You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2006/03/30 20:30:11 UTC

[Myfaces Wiki] Update of "Use Facelets with Tomahawk" by AndrewRobinson

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by AndrewRobinson:
http://wiki.apache.org/myfaces/Use_Facelets_with_Tomahawk

The comment on the change is:
Add tag handler code for Tree2

------------------------------------------------------------------------------
  Aaron Aston
  
  ----
+ In reference to the above "Facelet Tag Handler" for the tree2. Here is a component handler (tag handler) that works for tree2:
+ {{{
+ import java.util.Map;
+ 
+ import javax.faces.component.UIComponent;
+ 
+ import org.apache.myfaces.custom.tree2.HtmlTree;
+ import org.apache.myfaces.renderkit.JSFAttr;
+ 
+ import com.sun.facelets.FaceletContext;
+ import com.sun.facelets.tag.MetaRuleset;
+ import com.sun.facelets.tag.jsf.ComponentConfig;
+ import com.sun.facelets.tag.jsf.ComponentHandler;
+ 
+ public class Tree2TagHandler
+   extends ComponentHandler
+ {
+   public Tree2TagHandler(ComponentConfig cfg)
+   {
+     super(cfg);
+   }
+   
+   @Override
+   @SuppressWarnings("unchecked")
+   protected void onComponentCreated(FaceletContext ctx, UIComponent c, UIComponent parent)
+   {
+     super.onComponentCreated(ctx, c, parent);
+     
+     HtmlTree component = (HtmlTree)c;
+     
+     Map attrs = component.getAttributes();
+     ensureBoolean(attrs, JSFAttr.SHOW_NAV);
+     ensureBoolean(attrs, JSFAttr.SHOW_LINES);
+     ensureBoolean(attrs, JSFAttr.CLIENT_SIDE_TOGGLE);
+     ensureBoolean(attrs, JSFAttr.SHOW_ROOT_NODE);
+     ensureBoolean(attrs, JSFAttr.PRESERVE_TOGGLE);
+   }
+   
+   @SuppressWarnings("unchecked")
+   private void ensureBoolean(Map attributes, String attrName)
+   {
+     Object value = attributes.get(attrName);
+     if (value == null || !(value instanceof String)) return;
+     attributes.put(attrName, Boolean.valueOf((String)value));
+   }
+   
+   @Override
+   protected MetaRuleset createMetaRuleset(Class type)
+   {
+     return super.createMetaRuleset(type)
+       .alias("showNav", JSFAttr.SHOW_NAV)
+       .alias("showLines", JSFAttr.SHOW_LINES)
+       .alias("clientSideToggle", JSFAttr.CLIENT_SIDE_TOGGLE)
+       .alias("showRootNode", JSFAttr.SHOW_ROOT_NODE)
+       .alias("preserveToggle", JSFAttr.PRESERVE_TOGGLE);      
+   }
+ }
+ }}}
+ 
+ Also please node that you are welcome to use and contribute to the "tagHandlers" release of 
+ [http://jsf-comp.sourceforge.net jsf-comp]. I will probably add this to that project (tagHandlers.jar). There
+ is already one for <t:updateActionListener />
+ 
+ Andrew Robinson
+ 
+ ----
  I've put together a tomahawk-facelets library, that provides custom tag handlers for components that have 'special' attributes, requiring Boolean or Integer options. It includes a modified facelets library description XML.
  
  It can be obtained from [http://satva.skalasoft.com/~martin/dl/tomahawk-facelets.jar here]