有条件地呈现非JSF组件(普通香草HTML和模板文本) [英] Conditional rendering of non-JSF components (plain vanilla HTML and template text)

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

问题描述

我试图有条件地呈现< tr> ,因此我无法使用< h:panelGroup> ,因为它会呈现为< span>或< div>



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

 < h:outputFormat rendered =#{negotiator.maySend}> 
< tr>我的东西< / tr>
< / h:outputFormat>

这有效,但我不确定是否滥用 < h:outputFormat> - 在此之前,我使用了< h:outputLabel> ,但是这被呈现为<标签> 在IE中。



我也读过这个问题的答案,但正如上面提到的,他们不会为我工作, < tr> 如何不在JSF中渲染整个块? em>我无法使用< h:panelGroup> ,因为它会呈现为< span> 或<$ c



$ p $显然你没有仔细测试它。 < h:panelGroup> 将不会呈现任何内容,如果您没有指定最终会出现在客户端的属性,如 layout id styleClass 等。



<因此,这应该在技术上完全正常工作。

 < h:panelGroup rendered =#{negotiator.maySend} > 
< tr>我的东西< / tr>
< / h:panelGroup>

然而,更好的主要目的是使用 < ui:fragment> $ b

 < ui:fragment rendered =#{negotiator.maySend}> 
< tr>我的东西< / tr>
< / ui:fragment>

这也可以通过 < f:verbatim> ,但自从JSF 2.0专门为JSP中的使用而设计以来,这已被弃用。



另见:




在组件的哪个已经呈现的属性上> Ajax更新/渲染不起作用

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?

解决方案

I cannot use <h:panelGroup> as it will render to <span> or <div>

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和模板文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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