Facelets uses the jsfc attribute to convert HTML elements to their associated JSF components. This is rather helpful for fast prototyping as it allows you to create your views using a visual design tool. However I recently discovered this blog post by Cay Horstmann where he lays waste to the use of jsfc together with complex components such as h:dataTable.
Facelets使用jsfc属性将HTML元素转换为其关联的JSF组件。这对快速原型设计非常有用,因为它允许您使用可视化设计工具创建视图。然而,我最近发现了Cay Horstmann的这篇博客文章,他将jsfc与复杂组件(如h:dataTable)的使用浪费在一起。
This alarmed me as Cay Horstmann is 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 jsfc with Facelets ? and if not what's the problem it introduces.
这让我感到震惊,因为Cay Horstmann是我最喜欢的多本Java书籍的作者。然而,在尝试确定问题的范围/性质时,我的Google-fu技能没有产生任何结果,除了Ed Burns最近的帖子,他接近喜欢jsfc(并且他是JSF的所有联合规范领导者) 。所以我的问题很简单,是否建议将jsfc与Facelets一起使用?如果不是它引入的问题是什么。
1 个解决方案
#1
35
As you said, the jsfc
attribute is essentially usefull when you have to "convert" an HTML prototype to a JSF page. For example, when you have an HTML input text:
正如您所说,当您必须将HTML原型“转换”为JSF页面时,jsfc属性基本上是有用的。例如,当您有HTML输入文本时:
<input type="text" .../>
you can add the jsfc
attribute 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 here or here, the attribute jsfc
can 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:datatable
component, but we create a table with HTML code, using the JSF component ui:repeat
to iterate on rows.
在此示例中,我们不将此表链接到h:datatable组件,但我们使用JSF组件ui:repeat创建一个包含HTML代码的表,以迭代行。
As you can see, the jsfc
attribute 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:repeat
instead of the h:datatable
component).
如您所见,jsfc属性可用于将一个HTML组件转换为JSF页面中的一个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: jsfc
can 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。但是,一旦“真正的”开发开始,我认为最好避免使用这个组件...
#1
35
As you said, the jsfc
attribute is essentially usefull when you have to "convert" an HTML prototype to a JSF page. For example, when you have an HTML input text:
正如您所说,当您必须将HTML原型“转换”为JSF页面时,jsfc属性基本上是有用的。例如,当您有HTML输入文本时:
<input type="text" .../>
you can add the jsfc
attribute 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 here or here, the attribute jsfc
can 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:datatable
component, but we create a table with HTML code, using the JSF component ui:repeat
to iterate on rows.
在此示例中,我们不将此表链接到h:datatable组件,但我们使用JSF组件ui:repeat创建一个包含HTML代码的表,以迭代行。
As you can see, the jsfc
attribute 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:repeat
instead of the h:datatable
component).
如您所见,jsfc属性可用于将一个HTML组件转换为JSF页面中的一个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: jsfc
can 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。但是,一旦“真正的”开发开始,我认为最好避免使用这个组件...