JSF 渲染器 - 使用模板

发布于 2024-07-22 03:43:27 字数 910 浏览 6 评论 0原文

我想知道是否有人有使用某种模板语言在组件渲染器中生成 html 输出的经验。

在我看来,如果您的组件渲染在其生命周期中会发生变化,那么执行以下操作将很难维护。

 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");
...

我看过讨论使用 Velocity 作为渲染器模板语言的文章 (http://people. apache.org/~matzew/jsfvelocity.html),但我是在谈论其他 JSF 组件开发人员如何解决这个问题,以及对于如何处理这个问题是否存在更普遍的共识。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太阳哥哥 2024-07-29 03:43:28

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

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.

相权↑美人 2024-07-29 03:43:28

我不确定在渲染器中使用模板是否达成共识 - 当然, JSF 规范。 在 JSF 中使用模板的主要工作是通过 Facelets 在视图定义级别进行,但这在编写渲染器时几乎没有什么用处。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文