Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSF中的条件_Jsf_Jsf 2 - Fatal编程技术网

JSF中的条件

JSF中的条件,jsf,jsf-2,Jsf,Jsf 2,我可以在没有JSTL标记的情况下使用JSF执行条件逻辑吗 例如,我制作了一个复合组件,并想说明,如果指定了“id”属性,那么就定义“id”属性,但是如果没有指定“id”属性,那么就不要指定“id”属性 目前,我必须使用rendered属性,但其中有太多的重复,在指定id与否方面只有细微的区别 <composite:interface> <composite:attribute name="id" /> ... </composite:inte

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

例如,我制作了一个复合组件,并想说明,如果指定了“id”属性,那么就定义“id”属性,但是如果没有指定“id”属性,那么就不要指定“id”属性

目前,我必须使用rendered属性,但其中有太多的重复,在指定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>

...
它无论如何都是唯一的,因为componsite组件自己的客户端ID将被预先设置