How to dynamically change the content of a facet in a custom component?

Posted by romaintaz on Stack Overflow See other posts from Stack Overflow or by romaintaz
Published on 2010-05-03T12:59:10Z Indexed on 2010/05/03 13:58 UTC
Read the original article Hit count: 214

Filed under:
|

Hello,

Let's consider that I want to extend an existing JSF component, such as the <rich:datatable/>. My main requirement is to dynamically modify the content of a <f:facet>, to change its content.

What is the best way to achieve that? Or where is the best place in the code to achieve that?

In my faces-config.xml, I have the following declaration:

<faces-config>
    ...
    <component>
        <component-type>my.component.dataTable</component-type>
        <component-class>my.project.component.table.MyHtmlDataTable</component-class>
    </component>
    ...
    <render-kit>
        <render-kit-id>HTML_BASIC</render-kit-id>
        <renderer>
            <component-family>org.richfaces.DataTable</component-family>
            <renderer-type>my.renderkit.dataTable</renderer-type>
            <renderer-class>my.project.component.table.MyDataTableRenderer</renderer-class>
        </renderer>
        ...

Also, my my-project.taglib.xml file (as I use Facelets) looks like:

<facelet-taglib>
    <namespace>http://my.project/jsf</namespace>
    <tag>
        <tag-name>dataTable</tag-name>
        <component>
            <component-type>my.component.dataTable</component-type>
            <renderer-type>my.renderkit.dataTable</renderer-type>
        </component>
    </tag>

So as you can see, I have two classes in my project for my custom datatable: MyHtmlDataTable and MyDataTableRenderer. One of my idea is to modify the content of the <f:facet> directly in the doEncodeBegin() method of my renderer. This is working (in fact almost working), but I don't really think that's the better place to achieve my modification.

What do you think?

Technical information: JSF 1.2, Facelets, Richfaces 3.3.2, Java 1.6

© Stack Overflow or respective owner

Related posts about jsf

Related posts about richfaces