我有个用户编辑页面,editUser.xhtml,因为编辑用户和新增用户共用这个页面,所以用户ID需要在编辑状态设置成只读.<h:inputText styleClass="midInput" disabled="true"   value="#{userBean.user.userId}" rendered="#{userBean.type == 'update'}"  id="userId" required="true" requiredMessage="用户ID不能为空" maxlength="8">
                                                                  <f:validateLength minimum="1" maximum="8" />
                                                            </h:inputText>                                                             <h:inputText styleClass="midInput" value="#{userBean.user.userId}" rendered="#{userBean.type == 'add'}"  id="userId" required="true" requiredMessage="用户ID不能为空" maxlength="8">
                                                                  <f:validateLength minimum="1" maximum="8" />
得到异常:java.lang.IllegalStateException: component with duplicate id "editForm:userId" foundCaused by:
java.lang.IllegalStateException - component with duplicate id "editForm:userId" found
说userId重复 ,这种情况如何处理呢?

解决方案 »

  1.   

    editForm:userId看form里userId重名的改成别的。
      

  2.   

    改成了userid1,userid2  但 bean里的userid拿不到值了. 
      

  3.   

    bean里的userid也要做相应修改 
      

  4.   

    用js控制呗,进入编辑状态,就把id的所在的h:inputText 设为只读。
      

  5.   

    你的意思是 bean 里也定义俩 , userid1,userid2 然后去操作? 没有简单方法吗, 就为了一个一个输入框搞这么多修改感觉有些绕
      

  6.   

    用js控制呗,进入编辑状态,就把id的所在的h:inputText 设为只读。 =========
    js怎么控制? 给个例子贝 
      

  7.   

     userid1,userid2 然后去操作后台判断,看看那个有值,bean里面就set一下。这样可以把
      

  8.   

    userid1,userid2 然后去操作后台判断,看看那个有值,bean里面就set一下。这样可以把 
    =================
    这样应该是可以的, 就是代码有点ugly, 我不知道有没有别的简单的办法, js是一条路.
      

  9.   

    userid1,userid2 然后去操作后台判断,看看那个有值,直接url传参userId=有值的那个体。
      

  10.   

    上面说错了。js判断userid1,userid2 看看那个有值,直接url传参userId=有值的那个。
      

  11.   

    搞定了,用了这么一段  $(function() {
                val = $('#editForm').find("[name='editForm:userId']").val();            if(val != ""){              $('#editForm').find("[name='editForm:userId']").attr('readonly','true');            }        });
      

  12.   

    后台处理太麻烦了, 这一段jquery的程序就可以了