java 我应该使用 Facelets“jsfc”属性吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2337908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:40:56  来源:igfitidea点击:

Should I use Facelets "jsfc" attribute?

javajsffacelets

提问by Lars Tackmann

Facelets uses the jsfcattribute to convert HTML elements to their associated JSFcomponents. This is rather helpful for fast prototyping as it allows you to create your views using a visual design tool. However I recently discovered thisblog post by Cay Horstmannwhere he lays waste to the use of jsfctogether with complex components such as h:dataTable.

Facelets 使用jsfc属性将 HTML 元素转换为其关联的JSF组件。这对于快速原型设计非常有用,因为它允许您使用可视化设计工具创建视图。然而,我最近发现了Cay Horstmann 的这篇博文,他将jsfc与复杂的组件(如h:dataTable )结合使用

This alarmed me as Cay Horstmannis the author of multiple of my favorite Java books. However my Google-fu skills have yielded zero results when trying to determine the scope/nature of the problem, other than a recent post by Ed Burns, who seams to like jsfc(and he is after all the co-spec lead for JSF). So my question is simply, is it recommended to use jsfcwith Facelets ? and if not what's the problem it introduces.

这让我感到震惊,因为Cay Horstmann是我最喜欢的多本 Java 书籍的作者。然而,在尝试确定问题的范围/性质时,我的 Google-fu 技能产生了零结果,除了Ed Burns最近的一篇文章,他似乎喜欢jsfc(他毕竟是JSF的共同规范负责人) . 所以我的问题很简单,是否建议将jsfc与 Facelets一起使用?如果不是,它会带来什么问题。

回答by Romain Linsolas

As you said, the jsfcattribute is essentially usefull when you have to "convert" an HTML prototype to a JSF page. For example, when you have an HTML input text:

正如您所说,jsfc当您必须将 HTML 原型“转换”为 JSF 页面时,该属性基本上很有用。例如,当您有一个 HTML 输入文本时:

<input type="text" .../>

you can add the jsfcattribute in order to convert this HTML component into a JSF component:

您可以添加该jsfc属性以将此 HTML 组件转换为 JSF 组件:

<input type="text" jsfc="h:inputText" .../>

This is equivalent to writing the following JSF code:

这相当于编写以下 JSF 代码:

<h:inputText .../>

As stated in the Facelets documentation hereor here, the attribute jsfccan also be used to "map" Facelets components. For example, you can remove a part of the HTML code:

如此此处的 Facelets 文档所述,该属性jsfc还可用于“映射”Facelets 组件。例如,您可以删除部分 HTML 代码:

<span jsfc="ui:remove">
This won't be compiled either <h:outputText value="#{foo.bar}"/>
</span>

You can also create a table using this attribute:

您还可以使用此属性创建表:

<table>
    <tr jsfc="ui:repeat" value="#{dept.employees}" var="emp" class="#{emp.manager ? 'mngr' : 'peon'}">
       <td>#{emp.lastName}</td>
       <td>#{emp.firstName}</td>
    </tr>
</table>

In this example, we do not link this table to a h:datatablecomponent, but we create a table with HTML code, using the JSF component ui:repeatto iterate on rows.

在这个例子中,我们没有将此表链接到一个h:datatable组件,而是使用 HTML 代码创建一个表,使用 JSF 组件ui:repeat对行进行迭代。

As you can see, the jsfcattribute can be used to convert one HTML component into one JSF component in a JSF page. So for complex components, such as the datatable, you will have to use some workarounds (using ui:repeatinstead of the h:datatablecomponent).

如您所见,该jsfc属性可用于在 JSF 页面中将一个 HTML 组件转换为一个 JSF 组件。因此对于复杂的组件,例如数据表,您将不得不使用一些解决方法(使用ui:repeat而不是h:datatable组件)。

Another point is that you will not be able to use third-libraries components such as the ones proposed by RichFaces, IceFaces, Tomahawk, and so on. And these libraries are really one of the interests of JSF.

还有一点是你将无法使用诸如 RichFaces、IceFaces、Tomahawk 等提出的第三方库组件。而这些库确实是 JSF 的兴趣之一。

So to summarize: jsfccan be usefull to transform a HTML prototype into a JSF applications, essentially for creating Proof of Concepts or designing the general UI. However, I think it is better to avoid this component once the "real" development starts...

所以总结一下:jsfc将 HTML 原型转换为 JSF 应用程序非常有用,主要用于创建概念证明或设计通用 UI。但是,我认为一旦“真正的”开发开始,最好避免使用此组件......