Primefacesコンポーネント用の新しいレンダラーを作成しました。次に、この「新しい」コンポーネントを新しい名前空間で使用できるようにします。
そのために新しいtaglibを作成しました。
<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://www.whitebyte.com/commentbox</namespace>
<tag>
<tag-name>tree</tag-name>
<component>
<component-type>org.primefaces.component.Tree</component-type>
<renderer-type>commentbox.CustomTreeRenderer</renderer-type>
</component>
<attribute>
<description><![CDATA[Unique identifier of the component in a namingContainer.]]></description>
<name>id</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Boolean value to specify the rendering of the component, when set to false component will not be rendered.]]></description>
<name>rendered</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[An el expression referring to a server side UIComponent instance in a backing bean.]]></description>
<name>binding</name>
<required>false</required>
<type>javax.faces.component.UIComponent</type>
</attribute>
<attribute>
<description><![CDATA[Name of the client side widget.]]></description>
<name>widgetVar</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[A TreeNode instance as the backing model.]]></description>
<name>value</name>
<required>false</required>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Name of the request-scoped variable that'll be used to refer each treenode data during rendering.]]></description>
<name>var</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Specifies the ajax/client toggleMode. Default is false.]]></description>
<name>dynamic</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Specifies caching on dynamically loaded nodes. When set to true expanded nodes will be kept in memory. Default is true.]]></description>
<name>cache</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Javascript event to process when a tree node is clicked.]]></description>
<name>onNodeClick</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[TreeNode array to reference the selections.]]></description>
<name>selection</name>
<required>false</required>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Style of the main container element of tree.]]></description>
<name>style</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Style class of the main container element of tree.]]></description>
<name>styleClass</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Defines the selectionMode.]]></description>
<name>selectionMode</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Highlights nodes on hover when selection is enabled, set to false to disable highlighting.]]></description>
<name>highlight</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Unique key of the data presented by tree nodes.]]></description>
<name>datakey</name>
<required>false</required>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[When enabled, Displays slide effect during toggling of a node.]]></description>
<name>animate</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
</tag>
私もfaces-config.xmlにレンダリングを追加しました:
<render-kit>
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>commentbox.CustomTreeRenderer</renderer-type>
<renderer-class>commentbox.CustomTreeRenderer</renderer-class>
</renderer>
</render-kit>
新しいコンポーネントはEclipseにも表示されますが、ブラウザーでページを開くと、次のように表示されます。
javax.faces.FacesException: Cannot find component with identifier "tree" referenced from "j_idt62:j_idt76".
at org.primefaces.util.ComponentUtils.findClientIds(ComponentUtils.java:273)
at org.primefaces.util.AjaxRequestBuilder.addIds(AjaxRequestBuilder.java:102)
at org.primefaces.util.AjaxRequestBuilder.update(AjaxRequestBuilder.java:90)
at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:196)
at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeMarkup(CommandButtonRenderer.java:74)
at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeEnd(CommandButtonRenderer.java:49)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
at org.primefaces.component.outputpanel.OutputPanelRenderer.encodeEnd(OutputPanelRenderer.java:46)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
at org.primefaces.component.outputpanel.OutputPanelRenderer.encodeEnd(OutputPanelRenderer.java:46)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)