除非给出ID,否则不呈现没有style或styleClass的panelGroup [英] panelGroup without style or styleClass is not rendered unless ID is given

查看:66
本文介绍了除非给出ID,否则不呈现没有style或styleClass的panelGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://xmlns.jcp.org/jsf/html 的标记库,

According to the tag library for http://xmlns.jcp.org/jsf/html, a h:panelGroup is

旨在用于只有一个 可以嵌套UIComponent子级(例如,在构面的情况下). 如果存在样式"或"styleClass"属性,则 布局" 属性的值为"block",呈现"div" 元素, 输出样式"属性的值作为 样式"属性和"styleClass"属性的值作为 类别"属性的值.否则,如果布局"属性 不存在,或者布局"属性包含其他值 比 "block",呈现一个"span"元素,输出 将样式"属性作为样式"属性的值, 价值 "styleClass"属性的值作为"class"的值 属性.

Intended for use in situations when only one UIComponent child can be nested, such as in the case of facets. If the "style" or "styleClass" attributes are present, and the "layout" attribute is present with a value of "block", render a "div" element, outputting the value of the "style" attribute as the value of the "style" attribute and the value of the "styleClass" attribute as the value of the "class" attribute. Otherwise, if the "layout" attribute is not present, or the "layout" attribute contains a value other than "block", render a "span" element, outputting the value of the "style" attribute as the value of the "style" attribute, and the value of the "styleClass" attribute as the value of the "class" attribute.

如果是

<h:panelGroup id="id" layout="block">
    <!-- ... --->
</h:panelGroup>

<h:panelGroup layout="block" style="margin-right: 10px;">
    <!-- ... --->
</h:panelGroup>

正在渲染div:

<div id="id">
</div>

分别

<div style="margin-right: 10px;">
</div>

,但是当省略id(如果不想对update panelGroup)或style(如果不想对panelGroup设置样式)时,则没有div被渲染,结果HTML会弄乱布局.进一步研究JSF的领域,panelGroup也可以使用其rendered标志用于有条件地呈现子元素,但是如前所述,当省略两个提到的属性时,结果将有条件地呈现但没有div,例如

but when omitting the id (if one don't want to update the panelGroup) or the style (if one don't want to style the panelGroup) no div is being rendered and the resulting HTML can mess up ones layout. Furthermore exploring the realm of JSF, a panelGroup can also be used to conditionally render child elements using its rendered flag but as mentioned before when omitting the two mentioned attributes the result is rendered conditionally but without a div, such as

<h:panelGroup layout="block" rendered="true">
<it>Without DIV.</it>
</h:panelGroup>

导致

<it>Without DIV.</it>

查询之后,我想向Stackoverflow社区确认我理解是正确的,当不使用panelGroup作为命名容器或习惯样式时,其元素最好解决条件渲染部分(如果需要)使用ui:fragment和带有硬编码的div的布局部分.是这样吗?

After this inquiry I want to check with the Stackoverflow community that I understood it right that when not using a panelGroup as a naming container or to customary style its elements one is better off solving the conditional rendering part (if needed) using a ui:fragment and the layouting part with a hard-coded div. Is this so?

推荐答案

注意:我们正在谈论h:panelgroup是否将呈现任何HTML组件,但是除非render="false"在内的组件在任何情况下都不会被阻止呈现.

Note: we are talking about if h:panelgroup will render any HTML component, but unless render="false" the inner components are not blocked from rendering in any case.

h:panelgroup的行为树包含两个检查:

The behaviour tree of h:panelgroup consists of two checks:

  1. 是否至少设置了"id"或"style"或"styleClass"属性之一?
    :
    一种.如果layout ="block",则渲染<div>,否则
    b.呈现<span>(布局="乱码"或不存在)

  1. Is at least one of "id" or "style" or "styleClass" attributes set?
    Yes:
    a. Renders a <div> if layout="block", otherwise
    b. Renders a <span> (layout="gibberish" or non-existant)

否:

对布局属性的测试仅在上面的 1.之后进行.由于您的第三个示例进入分支,因此将其忽略.

The test for the layout attribute only comes after 1., above. Since your third example goes into the no branch, it is ignored.

这篇关于除非给出ID,否则不呈现没有style或styleClass的panelGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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