0
votes

I have a composite component (CC) that renders a inputText. I have a attribute called "autoFocus" in CC that should be rendered in inputText only when it values is true, see the code:

    <composite:attribute name="myAutoFocus" default="false" type="java.lang.Boolean"/>

So, inside composite:implementation i have the following:

<h:inputText pt:autofocus="#{cc.attrs.myAutoFocus}" />

In this way my autoFocus is always enable, because "autofocus=false" and "autofocus=true" is both TRUE. So i need a way to render the autoFocus looking for my CC attribute value.

1
Add your solution as an answer and mark it as accepted or delete your question if you feel that it will not help others in future. - Jorge Campos
I already created the correct answer but i can't accept it. - Ronaldo Lanhellas
You can, after some time. Just came back later. I don't remember the exact time. I gave you +1 for your effort though :) - Jorge Campos

1 Answers

2
votes

I used c:if to conditionally render the autofocus attribute via the f:passThroughAttribute from JSF 2.2 to solve my problem:

<h:inputText>
    <c:if test="#{cc.attrs.myAutoFocus}">
        <f:passThroughAttribute name="autofocus" value="autofocus"/>
    </c:if>
</h:inputText>