gpt4 book ai didi

jsf - JSF 中的条件

转载 作者:行者123 更新时间:2023-12-04 23:33:15 35 4
gpt4 key购买 nike

我可以在没有 JSTL 标签的情况下使用 JSF 执行条件逻辑吗?

例如,我制作了一个复合组件,并想说明,如果指定了“id”属性,则定义“id”属性,但如果未指定“id”属性,则不要指定“id”属性。

现在我必须使用渲染属性,但是那里有很多重复,在指定 id 或不指定 id 上只有细微的区别。

<composite:interface>
<composite:attribute name="id" />
...
</composite:interface>

<composite:implementation>
<!-- render this when id is specified, id attribute is defined -->
<h:selectOneMenu
id="#{cc.attrs.id}"
label="#{cc.attrs.label}"
value="#{cc.attrs.value}"
rendered="#{cc.attrs.id != null}" ...>
...
</h:selectOneMenu>

<!-- render this when id is not specified, id attribute is NOT defined -->
<h:selectOneMenu
label="#{cc.attrs.label}"
value="#{cc.attrs.value}"
rendered="#{cc.attrs.id == null}" ...>
...
</h:selectOneMenu>
</composite:implementation>

有什么想法可以避免这种重复并更容易地做有条件的事情吗?

谢谢 !

最佳答案

指定默认值 id你自己。

<h:selectOneMenu 
id="#{not empty cc.attrs.id ? cc.attrs.id : 'menu'}"
label="#{cc.attrs.label}"
value="#{cc.attrs.value}">
...
</h:selectOneMenu>

无论如何它都是唯一的,因为复合组件自己的客户端 ID 将被添加。

关于jsf - JSF 中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6434939/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com