Search code examples
jsf-2uirepeat

ui repeat separator char


Using jsf2 (see maven dependencies)

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.facelets</groupId>
        <artifactId>jsf-facelets</artifactId>
        <version>1.1.14</version>
    </dependency>

I found out that configuration of jsf doesn't be used by ui:repeat tag. If I redefine the separator char in web.xml

<context-param>
    <param-name>javax.faces.SEPARATOR_CHAR</param-name>
    <param-value>_</param-value>
</context-param>

a <ui:repeat> renderes a : anyway, this is why I can't use jquery for finding a div's Id in my custom component:

    <a href="#" onclick="toggleDiv('#{cc.clientId}Div')">
      <h:outputText value="#{cc.attrs.value}" />
    </a>
    <div id="#{cc.clientId}Div" style="display: none">...</div>

The HTML result of this component is:

    <a href="#" onclick="toggleDiv('j_idt12:0_j_idt18_0_j_idt24Div')">123456</a>
    <div id="j_idt12:0_j_idt18_0_j_idt24Div" style="display: none">
    ...
    </div>

As you can see, there's a : in j_idt12:0_j... that makes jquery functions invalid. What can I do about it? Is there a way to set a special ui separator char?


Solution

  • As to the jQuery "problem", just escape : as \\: or use the [id] selector instead. See also How to select JSF components using jQuery? By the way, I'd rather use fixed IDs instead of relying on JSF-generated IDs, otherwise your webapp is highly unportable.

    As to the <ui:repeat> problem, sorry, I can't reproduce it. But that Facelets 1.x dependency is highly suspicious. It would possibly only conflict with Facelets 2.x which is already bundled in JSF 2.x which in turn can indeed explain this problem. Get rid of that Facelets 1.x dependency altogether, you don't need it when already using JSF 2.x.