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.

4

2 回答 2

1

尝试将 Facelets 与 JSF 一起使用。他们可以将整个渲染器代码移动到一个 html 文件中。您不需要在 Java 中执行此操作。如果您需要一些样品,那么我可以分享。

于 2009-05-28T15:42:13.180 回答
0

我不确定在渲染器中使用模板是否有任何共识——当然,JSF 规范中没有任何内容。在 JSF 中使用模板的主要工作是在视图定义级别通过 Facelets,但这在编写渲染器时用处不大。

可能值得查看一些开源组件库构建过程,看看它们是否已经解决了这个问题。

于 2009-05-25T16:43:54.187 回答