Conditionally render element's attribute in a composite component

余生颓废 提交于 2019-11-30 14:04:05

You can use JSTL <c:if> to build the view conditionally and <f:attribute> to specify an attribute separately:

<h:inputText ...>
    <c:if test="#{not empty cc.attrs.size}">
        <f:attribute name="size" value="#{cc.attrs.size}" />
    </c:if>
</h:inputText>

An alternative is to specify a default for the composite component attribute:

<cc:attribute name="size" required="false" default="10" />

Additional to BalusC's post:

You must use

type="int" in the cc:attribute-tag :

cc:attribute name="maxlength" type="int"

I believe there is an alternate method for accessing attributes. I've used this with JSF 2 when accessing an attribute named with a java reserved keyword.

{cc.attrs['size']}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!