Jsf如何创建命名容器 [英] Jsf How to create a Naming Container

查看:70
本文介绍了Jsf如何创建命名容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSF应用程序中的ID重复存在问题.我已阅读这篇文章,其中一种可能的解决方案是使用命名容器.您能否举一些例子,说明如何使用命名容器来避免ID重复的问题?我使用Facelets.

I have a problem with duplicated ids in my JSF app. I've read in this post that one of the possible solutions is to use Naming Container. Can you give me some example how to use the Naming Container to avoid duplicated ids problem? I use Facelets.

推荐答案

这是使用JSF1.2和facelets对我有效的方法:

This is what worked for me using JSF1.2 and facelets:

我发现<ui:composition><ui:component>都不是命名容器,因此以相同的形式多次使用同一组件将失败,并且ID重复.这似乎是一个糟糕的设计,因为组件的重点是可重用性.为了解决这个问题,我在每个组件中都包含一个<f:subview>并将其ID设置为我的组件标签的参数:

I discovered that neither <ui:composition> nor <ui:component> is actually a naming container, so using the same component more than once in the same form would fail with a duplicate ID exception. This seems like a bad design, as the whole point of components is re-usability. To get around this problem I include a <f:subview> within each component and set the id on it as a parameter of my component tag:

myComponent.xhtml:

myComponent.xhtml:

<ui:component>      
    <f:subview id="#{id}">
        ....component code
    </f:subview>
</ui:component>

并且在其他页面上使用它很简单(正确设置了taglib.xml和web.xml之后):

and the using it on other pages is simple (after setting up taglib.xml and web.xml correctly):

<myTagLib:myComponent id="myCompA" />

这篇关于Jsf如何创建命名容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆