How do I dynamically change the content of a facet in a custom component?
Suppose I want to extend an existing JSF component eg <rich:datatable/>
. My main requirement is to dynamically change the content <f:facet>
in order to change its content.
What is the best way to achieve this? Or where is the best place in your code to achieve this?
In mine 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 file my-project.taglib.xml
(how I use Facelets) looks like this:
<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 ideas is to change the content <f:facet>
directly in the method of doEncodeBegin()
my renderer. It works (actually almost works ), but I really don't think the best place for my modification is.
What do you think?
Technical info: JSF 1.2, Facelets, Richfaces 3.3.2, Java 1.6
a source to share