隨筆-112  評論-73  文章-0  trackbacks-0

          在JSF組件開發(fā)過程遇到一個問題.就是當(dāng)自己開發(fā)的組件再次提交的時候會提示一個錯誤:

          Duplicate component ID ... found in view.

          意思是說在ViewRoot中已經(jīng)存在一個同名的組件了.這是JSF不允許的.

          后來在網(wǎng)上苦苦的找....終于找到這個一篇:http://www.jroller.com/mert/entry/duplicate_component_id_found_in 部分原文如下:


          I stated some possible solutions for the exception.

          1. If you are dynamically adding child components to a UIComponent, also set the id of the child components explicitly.

          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,

          <c:forEach>
          <theComponent id="componentId + unique value for each iteration" />
          </c:forEach>

          The id for theComponent should be composed with a value that is unique each iteration.

          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.

          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 :)

          其中第三條正是我遇到的問題的原因的答案.就是在自己開發(fā)的組件中,只需在tld文件中指定id屬性,不需在tag.class中再設(shè)置id屬性.具體的是不能再有setId(String id)這樣的方法了.因為父類UIComponentELTag中已存存在這個屬性.而且是在tld中一定要設(shè)置成靜態(tài)的String類型.不能是ValueExpression類型

          在tld文件中這樣設(shè)置id屬性

          <attribute>
          <name>id</name>
          <rtexprvalue>false</rtexprvalue>
          <type>java.lang.String</type>
          </attribute>
          然后把tag class中的id 屬性和setId方法去掉.

          ^_^

          一點感想:

          成功和失敗真的是一步的距離、一時的閃念。在尋找答案的過程中真是想放棄自己開發(fā)的這個組件,但另一種信念使我沒有放棄,最后終于解決了。

          用一個小小組件中的一個問題的解決來說成功與失敗也許是小題大做,但這個成功的信念是一樣的。只要堅持就會有結(jié)果!


          Technorati :

          posted on 2007-08-18 09:13 Libo 閱讀(2004) 評論(1)  編輯  收藏

          評論:
          # re: JSF組件ID重復(fù)的問題 2007-08-18 13:47 | Alex
          自己開發(fā)組建? 精神可嘉,不過個人認(rèn)為沒有太大的實際價值  回復(fù)  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 拉孜县| 禄丰县| 兴国县| 阳高县| 兴隆县| 岚皋县| 普兰店市| 巴林右旗| 金川县| 徐汇区| 大丰市| 察隅县| 星子县| 安阳县| 金川县| 贺州市| 格尔木市| 维西| 临西县| 任丘市| 鞍山市| 陵水| 历史| 江门市| 洪江市| 五莲县| 新密市| 出国| 东兴市| 木兰县| 车险| 界首市| 饶河县| 平凉市| 鄂尔多斯市| 溧阳市| 武穴市| 潞西市| 岳普湖县| 岳阳市| 古蔺县|