【发布时间】:2011-11-01 17:15:34
【问题描述】:
我编写了一个复合组件,想使用保留的 EL #{component.clientId} 进行 JQuery 绑定。为了在页面的另一个地方(组件之外)使用这个检索到的 clientId,我使用 JSTL 将它存储在视图范围变量中。奇怪的是,JSTL 似乎阻止了将其 id 附加到其子级之前的自然复合组件行为(NamingContainer 行为)。我知道 JSTL 有点棘手,因为生命周期的事情,会干扰其他组件(例如ui:repeat),但在这里我不理解这种行为。
一些具体的代码比这个长篇演讲更好:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
[…]
</composite:interface>
<composite:implementation>
<rich:dataTable id="mySoLovedDataTable" […]>
#{component.clientId}
<!-- Commenting or uncommenting this line make the whole point -->
<c:set var="targetClientId" value="#{component.clientId}" scope="view" />
[…]
</rich:dataTable>
</composite:implementation>
</html>
注释行后,#{component.clientId} 会给出类似j_idt261:mySoLovedDataTable 的内容。
注释掉该行后,它只给出mySoLovedDataTable。
【问题讨论】:
-
澄清一下,您想使用组件外部的ID,对吧?
-
没错。编辑澄清。
-
但要清楚一点,我在这里感兴趣的一点是 JSTL 代码对
NamingContainer的prependId行为的影响。
标签: jsf-2 jstl composite-component naming-containers