Rendering custom dataTable: is it possible?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mus_Cypriotis
Posted On:   Friday, October 20, 2006 08:56 AM

For a number of reasons, I decided to code my own dataTable, which encodes children slightly different from usual. As you all may know, the usual extension of dataTables and other JSF components are made just writing new Tag extension class and the extending component class, where only 2 methods usually are overriden: encodeBegin and encodeEnd. Here, the encodeChildren was overriden so that I can put any attributes to tbody and thead tags. Is there a problem? Yes it is, and -=BIG=- one. It consists in recursive child rendering -- once getRendersChildren() returns true , you -=MUST=- take care of all children. UNFORTUNATELY (or I don't know?) JSF frame   More>>

For a number of reasons, I decided to code my own dataTable,
which encodes children slightly different from usual.


As you all may know, the usual extension of dataTables and other JSF components are made just writing new Tag extension class and the extending component class, where only 2 methods usually are overriden: encodeBegin and encodeEnd.


Here, the encodeChildren was overriden so that I can put any attributes to tbody and thead tags.


Is there a problem? Yes it is, and -=BIG=- one. It consists in recursive child rendering -- once getRendersChildren() returns true , you -=MUST=- take care of all children.


UNFORTUNATELY (or I don't know?) JSF framework does not provide such a method. Of course, I haven't stopped at this point, and the internet has provided a useful small method for rendering children recursively:

			
static void encodeRecursive(FacesContext pContext, UIComponent pComponent) throws IOException {
if ( ! pComponent.isRendered()) return;
pComponent.encodeBegin(pContext);
if (pComponent.getRendersChildren()) {
pComponent.encodeChildren(pContext);
} else for (Object component: pComponent.getChildren()) {
encodeRecursive(pContext, (UIComponent) component);
}
pComponent.encodeEnd(pContext);
}

It's small, it's recursive, it's workable...
Does someone see error in it? No? But there exist one, which put me on googling and forum visiting. This is: if component has getRendererType() != null , the renderer's methods encodeXXX(...) must be called. And now try to call that renderer!


Method getRenderer(FacesContext) is protected in class UIComponentBase, so you are aprived to call it directly.


If you try to call pContext.getRenderKit().getRenderer(pComponent.getFamily(), pComponent.getRendererType()) , it simply returns null.


Maybe all works fine and I am just flaming? Isn't true.
For instance, resulted just in rendering of enclosing with a class attribute inside it...


Any ideas? Or I am the first guy who discovered it?
Hope you may have a clue. Thanks in advance!

   <<Less
About | Sitemap | Contact