在JSF组件开发过程遇到一个问题.就是当自己开发的组件再次提交的时候会提示一个错误:
Duplicate component ID ... found in view.
意思是说在ViewRoot中已经存在一个同名的组件了.这是JSF不允许的.
后来在网上苦苦的找....终于找到这个一篇:http://www.jroller.com/mert/entry/duplicate_component_id_found_in 部分原文如下:
I stated some possible solutions for the exception. <o:p>
1. If you are dynamically adding child components to a UIComponent, also set the id of the child components explicitly.
<o:p>2. If you are using JSTL tags like forEach, if, choose and when, make sure you specify unique ids for the components defined between these tags at each iteration. For example,
<o:p><c:forEach>
<theComponent id="componentId + unique value for each iteration" />
</c:forEach><o:p>
<o:p>The id for theComponent should be composed with a value that is unique each iteration.</o:p>
<o:p>3. If you are developing a custom JSF Component just define id attribute in .tld file. You don?t need to specify id property in tag class. Because it inherits the id from UIComponentBase. So you should also set the properties of the super class within setProperties() method of the component.
<o:p>4. You cannot determine an id like "_idX" manually in your jsp source code, it is not a valid component identifier (cannot start with "_" ) so re-check the previous steps :)
其中第三条正是我遇到的问题的原因的答案.就是在自己开发的组件中,只需在tld文件中指定id属性,不需在tag.class中再设置id属性.具体的是不能再有setId(String id)这样的方法了.因为父类UIComponentELTag中已存存在这个属性.而且是在tld中一定要设置成静态的String类型.不能是ValueExpression类型
在tld文件中这样设置id属性
<attribute>
<name>id</name>
<rtexprvalue>false</rtexprvalue>
<type>java.lang.String</type>
</attribute>
然后把tag class中的id 属性和setId方法去掉.
^_^
一点感想:
成功和失败真的是一步的距离、一时的闪念。在寻找答案的过程中真是想放弃自己开发的这个组件,但另一种信念使我没有放弃,最后终于解决了。
用一个小小组件中的一个问题的解决来说成功与失败也许是小题大做,但这个成功的信念是一样的。只要坚持就会有结果!
<!---->
Technorati : JSF
分享到:
相关推荐
JSF分页组件2,JSF分页组件2
一些关于jsf组件树的动态添加,删除操作资料
JSF组件包含若干个Java类和配置文件。为创建一个自定义JSF组件,您需要开发一个扩展JSF基本组件类的Java类;为默认呈现软件包开发呈现程序;开发一个将在JSP页面中用于描述标签的Java类;编写一个标签库定义(TLD)...
JSF 组件WebSphere 平台配置使用说明
一个上传文件的jsf组件
javaserver faces组件开发源码,原文在我的Blog里面
JSF自定义组件学习的好教材
JSF 组件开发.rar
JSF UI 组件详解
只要介绍JSF中各个组件标签的用法,对初学者来说是个很不错的资料哦!
JSF创建自定义组件
创建JSF自定义组件
浅显得讲述了自定义jsf组件得编写
一个纯JSF1.2写的日历组件,想了解JSF组件编写的可以用来参考
JSF2.0实战 - 4、自定义组件 示例代码
一步一步教你如何在jsf中自定义组件,简单易学,有程序完整代码。通过这个小demo你可以进一步开发复杂的组件。
1. JSF生命周期与组件概述 1.1 JSF生命周期 1.2 概述自定义组件 2. 简单实例 2.1 编码、解码 2.2 组件标签 2.3 使用自定义组件 2.4 自定义Renderer
要通过几个实例来详细介绍如何自定义 JSF 组件。
Ext组件转化成JSF Ext组件转化成JSF ext组件转化成JSF Ext组件转化成JSF Ext组件转化成JSF ext组件转化成JSF
unofficial-primefaces, PrimeFaces JSF组件的非官方镜像 PrimeFaces非官方产品。 PrimeFaces JSF组件的非官方镜像为什么?新Maintanance策略没有从 PrimeFaces 3.5开始的免费版本。这个工作计划旨在提供免费可用的...