替代ui:JSF中的片段 [英] Alternative to ui:fragment in JSF

查看:115
本文介绍了替代ui:JSF中的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搜索支持的方式来渲染JSF中的一段代码,我通常使用这种方法:

I'm searching a supported way to render a section of code in JSF, I usually use this approach:

<ui:fragment rendered="#{condition}">
   <h:outputText value="text 1"/>
   <h:outputText value="text 2"/>
   <h:outputText value="text 3"/>
</ui:fragment>

由于ui:fragment不支持渲染大部分IDE(如netbeans将其标记为错误但是它因为JSF参数是继承的。

Since ui:fragment doesn't support rendered most of IDE (like netbeans mark it as error BUT it works because in JSF parameters are inherited.

解决这个问题的一种方法是使用另一种结构(例如,如果你使用SEAM)你可以使用

One way to solve this is to use another structure (for example if you use SEAM) you can use

<s:div rendered="#{condition}">
   ....
</s:div>

另一种方法是在所有内部内容中设置渲染,如下所示:

Another way is to set the rendered in all inner content like this:

<h:outputText value="text 1" rendered="#{condition}"/>
<h:outputText value="text 2" rendered="#{condition}"/>
<h:outputText value="text 3" rendered="#{condition}"/>

但我不喜欢这种方式,因为你必须将渲染添加到每个元素。

But I don't like this way because you have to add the rendered to each element.

另一种方法是使用< c:if test =#{condtion}> 但是c:如果从JSF中删除元素树而不是你一直想做的事特别是如果你使用AJAX。

Another way would be to use <c:if test="#{condtion}"> BUT c:if remove the elements from the JSF tree and that not what you always want to do especially if you use AJAX.

所以你们有其他的解决方案吗?

So you guys have another solutions?

推荐答案


由于 ui:fragment 不支持渲染大部分IDE(如Netbeans将其标记为错误但是它有效,因为在继承了JSF参数)

Since ui:fragment doesn't support rendered most of IDE (like Netbeans mark it as error BUT it works because in JSF parameters are inherited)

这实际上是JSF 2.0 Facelets标签文件声明中的一个错误(在Mojarra中,这是 com / sun / faces / metadata / taglib / ui.taglib.xml file)。标记文件声明中忽略了呈现的属性(以及 JSF 2.0 < ui:fragment> 标签文档),虽然它真的存在于 UIComponent 中。 IDE验证基于标记文件声明,因此它会产生误导性验证错误。这个问题在JSF 2.1中得到修复,缺少的属性被添加到标记文件声明中(以及 JSF 2.1 < ui:fragment> 标签文档)。

This is actually a bug in JSF 2.0 Facelets tag file declaration (in Mojarra, that's the com/sun/faces/metadata/taglib/ui.taglib.xml file). The rendered attribute is overlooked and missing in the tag file declaration (and also in the JSF 2.0 <ui:fragment> tag documentation), while it is really present in the UIComponent. The IDE validation is based on the tag file declarations and hence it gives a misleading validation error. This issue is fixed in JSF 2.1, the missing attribute is added to the tag file declaration (and also in the JSF 2.1 <ui:fragment> tag documentation).

如果只是忽略IDE警告或升级到JSF 2.1不是一个选项,那么你可以考虑使用 < h:panelGroup> component 而不是:

If either just ignoring the IDE warnings or upgrading to JSF 2.1 is not an option, then you can consider using the <h:panelGroup> component instead:

<h:panelGroup rendered="#{condition}">
   <h:outputText value="text 1"/>
   <h:outputText value="text 2"/>
   <h:outputText value="text 3"/>
</h:panelGroup>

如果你没有指定 id style styleClass 和类似的属性,否则一个简单的< span> ; 将被呈现。

It outputs nothing anyway if you don't specify the id, style, styleClass and like attributes, else a simple <span> will be rendered.

如果您拥有的只是普通的HTML(即没有JSF组件),那么您也可以考虑使用< f:verbatim>

If all what you have is plain vanilla HTML (i.e. no JSF components), then you can also consider using <f:verbatim>.

<f:verbatim rendered="#{condition}">
   text 1
   text 2
   text 3
</f:verbatim>

然而,< f:verbatim> 已弃用(顺便提一下,这也是一个纪录片错误, JSF 2.0 < f:verbatim> 标签文档未提及弃用,但 JSF 2.1 < f:verbatim> 标签文档确实如此。

However, the <f:verbatim> is deprecated in JSF 2.0 (which in turn has also a documentary bug by the way, the JSF 2.0 <f:verbatim> tag documentation does not mention deprecation, but the JSF 2.1 <f:verbatim> tag documentation does).

这篇关于替代ui:JSF中的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆