views:

22

answers:

1

I created a Facelet tag for rendering a textinput with a label. That's very helpful when for avoiding repeating the same code over and over again.

Though I'm struggling with handling different use cases within this single tab (date vs. text, required vs. not required, textarea vs. normal text etc.)

I ended up with having multiple tags within my component all with a more or less complicated rendered attribute, like shown here:

    <h:inputText    
            onblur="makeNotEmpty(this)"
            onfocus="makeNotEmptyFocus(this)"
            id="#{cid}"
            value="#{value}"
            rendered="#{textarea!='true' and type!='email' and notrequired!='true' and nullablenumber!='true'}"
            style="#{style }"   
            required="true"
            disabled="#{disabled }">        
            <f:validator validatorId="notnull"/>    

    </h:inputText> 
    <h:inputText                    
        onblur="    
            makeNotEmpty(this)"
        onfocus="makeNotEmptyFocus(this)"
        id="#{cid}"
        value="#{value}"
        rendered="#{type=='email'}"
        style="#{style }"
        required="true"
        disabled="#{disabled }">            
        <f:validator validatorId="email" />
        <f:validator validatorId="notnull"/>
    </h:inputText> 

Of course that's no optimal and rather tedious to write. One other problem I think is that using this approach I have multiple components with the same ID in the component tree (I'm not sure if that's a problem as only one item having the same ID is rendered at one time but I saw some strange problems re-creating the page tree making me belive it's a problem)

I'm using ICEFaces 1.8.2 (but the problem should be implementation independent). What's the solution for this? Using ? Something else? Thanks!

+1  A: 

You can put <f:validator> in a JSTL <c:if>. It will be created during tag build time.

<html xmlns:c="http://java.sun.com/jsp/jstl/core"&gt;
...
<c:if test="#{type eq email}"><f:validator validatorId="email" /></c:if>

By the way, IceFaces isn't a JSF implementation, it's a JSF component library which is supposed to run on top of a JSF implementation.. Mojarra and MyFaces are JSF implementations.

BalusC
thanks, that's how I will do it. and I never called ICEfaces a JSF implementation ;)my original problem was not solved by that though... I found the problem: is was that ICEFaces seems to have issues when you have a <ice:panelGroup> with a binding and when that panelGroup contains facelet components. Having this scenario I always had the problem that the component tree was completely messed up when the page was rebuilt (it was OK the first time I visit the page). With messed up I mean that some controls weren't shown at all or labels were rendered as buttons aso.,probably an IceFaces bug
hubertg
Your phrase *I'm using ICEFaces 1.8.2 (but the problem should be implementation independent)* was suggesting that. Further I don't do IceFaces, so I can't go in detail of this problem.
BalusC
no problem, thanks anyway!
hubertg
You're welcome.
BalusC