Conditionally render element's attribute in a composite component

后端 未结 3 1196
[愿得一人]
[愿得一人] 2021-01-02 17:52

I have the following composite component:




        
相关标签:
3条回答
  • 2021-01-02 18:06

    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" />
    
    0 讨论(0)
  • 2021-01-02 18:12

    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']}

    0 讨论(0)
  • 2021-01-02 18:20

    Additional to BalusC's post:

    You must use

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

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

    0 讨论(0)
提交回复
热议问题