JSF:将带有更改的Renderer的组件与其他Namespace一起使用

时间:2012-11-05 17:04:08

标签: jsf jsf-2 primefaces custom-component taglib

我为primefaces组件编写了一个新的渲染器,现在我想在新的命名空间下使这个“new”组件可用:

我为此创建了一个新的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)

1 个答案:

答案 0 :(得分:0)

解决方案是创建“整个”组件并在taglib中注册,如下所述:

https://stackoverflow.com/a/10569044/441907

(我没有注册taglib只是将其放入有效的类中的META-INF中。)