【发布时间】:2014-06-15 20:51:14
【问题描述】:
TL;DR 是否有类似 Composite 的 cc.clientId 的东西会给我自定义标签的 id?
详情: 我想要一个可以呈现标签、值和图标的自定义标签。单击该图标时,应该会打开一个 Bootstrap 模式来编辑该值。
<ui:composition>
<div> #{field.label}: #{field.value}
<a class="icon-pencil" data-target="#editForm" data-toggle="modal">
</div>
<h:form id="editForm" class="modal hide fade" role="dialog" ...>
... there's an input here linked to field.value ...
</h:form>
</ui:composition>
我可以将标签与<my:editor /> 一起使用。当我在 ui:repeat 中这样做时,会在 editForm 前面添加一个 id,以便它使用 id j_idt104:editForm 呈现。所以我需要修改数据目标以包含 id。
如果使用复合组件,这将非常容易,因为我可以通过 cc.clientId 访问 id:
data-target="\##{cc.clientId}\:editForm"
但是,我无法让它与自定义标签一起使用,因为我不知道可以让我访问 id 的 EL 表达式(或其他东西)。我可能会等到页面加载后,然后使用 jQuery 检查 id 并在事后设置数据目标,但我希望有一个更纯 JSF 的解决方案。
我目前正在使用 JSF 2.1 和 Bootstrap 2.3。
【问题讨论】:
-
标签文件不这样做。它们与没有
NamingContainers 的复合组件相反。那个自动生成的 ID 实际上不是来自<ui:repeat>左右的<my:editor>左右吗? -
确实如此。我正在为支持 bean 的列表中的项目重复编辑器。
标签: jsf jsf-2 twitter-bootstrap-2