本文介绍了非 JSF 组件的条件渲染(普通 HTML 和模板文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试有条件地渲染 因此我不能使用 因为它会渲染到 ;或

我目前的(工作)方法如下:

<tr>我的东西</tr></h:outputFormat>

这有效,但我不确定这是否是滥用 <h:outputFormat> 的方式 - 在此之前我使用了 <h:outputLabel> 但是这在 IE 中被渲染为 .

我也阅读了这个问题的答案,但如上所述,由于 <tr>:如何在 JSF 中不渲染整个块?

解决方案

显然你没有仔细测试它.<h:panelGroup> 如果您不指定应该在客户端结束的属性,例如 layoutid,则不会呈现任何内容、styleClass

因此,这在技术上应该可以正常工作.

<tr>我的东西</tr></h:panelGroup>

然而,更好的主要目的是使用 .

<tr>我的东西</tr></ui:fragment>

顺便说一下,这也可以使用 ,但自 JSF 2.0 起已弃用,因为它专为在 JSP 中使用而设计.

另见:

I'm trying to conditionally render a <tr> therefore I cannot use <h:panelGroup> as it will render to <span> or <div>

My current (working) approach is the following:

<h:outputFormat rendered="#{negotiator.maySend}">
    <tr> my tr stuff </tr>
</h:outputFormat>

This works, but I'm not sure if that's the way to abuse <h:outputFormat> - before that I used <h:outputLabel> but this was rendered to <label> in IE.

I have also read the answers to this question, but as mentioned above, they won't work for me because of the <tr>: How to not render whole block in JSF?

解决方案

Apparently you didn't test it carefully. The <h:panelGroup> won't render anything if you don't specify attributes which should end up in the client side, like layout, id, styleClass, etc.

Thus, this should technically perfectly work fine.

<h:panelGroup rendered="#{negotiator.maySend}">
    <tr> my tr stuff </tr>
</h:panelGroup>

However, better for the main purpose would be to use <ui:fragment>.

<ui:fragment rendered="#{negotiator.maySend}">
    <tr> my tr stuff </tr>
</ui:fragment>

This is by the way also possible with <f:verbatim>, but this is deprecated since JSF 2.0 as it's designed specifically for usage in JSP.

See also:

这篇关于非 JSF 组件的条件渲染(普通 HTML 和模板文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:13