3 Replies Latest reply on Jun 19, 2008 9:27 PM by halylam

    DuplicateClientIDException

    ssilvert

      Question moved to its own thread.


      Hi Stan,

      You said that we should put an id for every web component in a jsf page so that we can test JSFUnit test.

      So, I created a web application using JAVA Persistence and used JSFUnit Test. My problem is that: my jsf page content a table have many rows. Every row is loaded form a table in database. And every row has a command link to edit data and save to database. I want to test these command link but when I put id in every tag like this <h:commandLink value="Edit" action="#{animal.editSetup}" id="editCurrentAnimalItem"> . I received error like this "editCurrentAnimalItem matches more than one JSF component ID. Use a more specific ID suffix. Suffix matches: j_id_id19:table1:0:editCurrentAnimalItem, j_id_id19:table1:1:editCurrentAnimalItem"

      and here my test method:

      public void testClickEditAnimal() throws IOException, SAXException {
      this.client.clickCommandLink("showAnimals");
      this.client.clickCommandLink("editCurrentAnimalItem");
      this.client.setParameter("kind", "Thú ăn thịt");
      this.client.setParameter("name", "Chó sói");
      this.client.setParameter("pavilion", "2");
      this.client.setParameter("weight", "130");
      this.client.clickCommandLink("saveAnimal");
      JSFServerSession server = new JSFServerSession(this.client);
      assertEquals("/animal/Detail.jsp", server.getCurrentViewID());
      }

      I knew the "ID" loaded from database is duplicated. Can you give me an advise or a solution?
      If you haven't understood clearly my question, you can reply to me.

      I'm looking forward to hearing from you

      Best regards

      HaLy

        • 1. Re: DuplicateClientIDException
          ssilvert

          The JSFUnit API always searches for ID's based on a simple match of the ClientID suffix you passed in. So sometimes, that suffix can match more than one ClientID. However, the full ClientID will always be unique and the DuplicateClientIDException will tell you about all the matches. Se more info here:
          http://wiki.jboss.org/wiki/UsingComponentIDs

          So in your case, you need to pass in either "0:editCurrentAnimalItem" or "1:editCurrentAnimalItem".

          Stan

          • 2. Re: DuplicateClientIDException
            halylam

            Hi Stan,

            I tried your advise but another error appear:

            "HTTP Status 500 -

            type Exception report

            message

            descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

            exception

            javax.servlet.ServletException: java.lang.IllegalArgumentException: 1:editCurrentAnimalItem

            root cause

            java.lang.IllegalArgumentException: 1:editCurrentAnimalItem

            note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1_02 logs."


            About more my problem, if I only have one row in table, it's OK. But when I have more than one row, it's error. I think that when I have many rows, the table will set ID="editCurrentAnimalItem" loop for every row, so the method don't know get which id.

            Thank for your help

            HaLy

            • 3. Re: DuplicateClientIDException
              halylam

              Hi Stan,

              Sorry, I've mistaked. Now It's ok.

              Thanks for your help

              HaLy