mga*_*mer 7 jsf facelets naming-containers
我的JSF应用程序中存在重复ID的问题.我在这篇文章中读过,其中一个可能的解决方案是使用命名容器.你能给我一些例子来说明如何使用命名容器来避免重复的id问题吗?我使用Facelets.
Nag*_*alf 12
这对我来说使用JSF1.2和facelets是有用的:
我发现既不是<ui:composition>也不<ui:component>是命名容器,因此在同一表单中多次使用相同的组件会因重复的ID异常而失败.这似乎是一个糟糕的设计,因为组件的重点是可重用性.为了解决这个问题,我<f:subview>在每个组件中包含一个并在其上设置id作为我的组件标记的参数:
myComponent.xhtml:
<ui:component>
<f:subview id="#{id}">
....component code
</f:subview>
</ui:component>
Run Code Online (Sandbox Code Playgroud)
并且在其他页面上使用它很简单(在正确设置taglib.xml和web.xml之后):
<myTagLib:myComponent id="myCompA" />
Run Code Online (Sandbox Code Playgroud)