views:

569

answers:

2

I was wondering if anyone has experience with using some kind of templating language for generating the html output in the component's renderer.

It seems to me that doing stuff like the following is difficult to maintain if your component rendering will suffer changes during its life.

 writer.write('\n');
 writer.startElement("script", null);
 writer.writeAttribute("type", "text/javascript", null);
 writer.writeAttribute("language", "Javascript", null);
 writer.write("var checkbox_off = \"" + CHECKBOX_OFF_IMAGE_PATH + "\";\n");
 writer.write("var checkbox_on = \"" + CHECKBOX_ON_IMAGE_PATH + "\";\n\n");
 writer.write("cache1 = new Image("
                    + CHECKBOX_IMAGE_WIDTH
                    + ","
                    + CHECKBOX_IMAGE_HEIGHT
                    + ");\n");
 writer.write("cache1.src=checkbox_off;\n");
...

I have seen articles discussing the use of Velocity as the renderer templating language (http://people.apache.org/~matzew/jsfvelocity.html) but I was wordering how other JSF component developers have solved this problem and whether there is a more general consensus on how to handle this problem.

A: 

I'm not sure there is any consensus on using templates in the renderers - certainly, there isn't anything in the JSF specification. The main effort for using templates in JSF is at the view definition level via Facelets, but this is of little use when writing renderers.

It may be worth looking at some of the open source component library build processes to see if they've already tackled this issue.

McDowell
+1  A: 

Try using Facelets with JSF. Their you can move whole Renderer code in a html file. You dont need to do it in Java. If you need some sample then i can share that.

Pavitar Singh
Sure a sample would be great