ui:repeat using the same client id. c:foreach works fine

淺唱寂寞╮ 提交于 2019-12-08 16:27:31

I did a quick test on local environment (Mojarra 2.0.4 on Tomcat 7.0.11). Using #{cc.clientId} gives you an unique ID back everytime.

<ui:repeat value="#{bean.items}" var="item">
    <cc:test />
</ui:repeat>

with

<cc:implementation>
    <div id="#{cc.clientId}_foo">foo</div>
</cc:implementation>

Here's the generated HTML source:

<div id="j_idt6:0:j_idt7_foo">foo</div>
<div id="j_idt6:1:j_idt7_foo">foo</div>
<div id="j_idt6:2:j_idt7_foo">foo</div>

This should be sufficient for your functional requirement. You might only want to escape the default separator : or to replace it by a custom separator since it's a reserved character in CSS selectors.


Update: so you want to escape it, you should then replace : by \: and not by _.

var clientId = clientIdOld.replace(/:/g, '\\:');

(the /:/g is a regex which ensures that all occurrences will be replaced and the double slash is just to escape the slash itself in JS strings, like as you normally do in Java strings)

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