6 Replies Latest reply on May 3, 2009 10:05 PM by nitm

    duplicate Id problem

    nitm

      hey everyone,


      i created a component for a user panel (will display the name of the user with some actions if logged in and login/register links if not) and i call it from my base template.


      the code for this component:


      <h:panelGroup layout="block" id="userPanel" rendered="#{identity.loggedIn}">
              #{identity.username} [<a href="#" onclick="return false;">Log Out</a>|<a href="#" onclick="return false;">Profile</a><a href="#">Settings</a>]
      </h:panelGroup>
      <h:panelGroup layout="block" id="userPanel" rendered="#{not identity.loggedIn}">
              Guest [<a href="#" onclick="page.showAuthenticationForms(); return false;">Log In / Register</a>]
      </h:panelGroup>



      when i try to open the page i get this error:



      duplicate Id for a component userPanel

      i don't get why this happens since only one of the panelGroups should be rendered.
      what can cause this?
      i am using seam 2.1.1 with jboss as 5.0
      thanks!
      nitzan;


        • 1. Re: duplicate Id problem

          Simple: Because you have 2 panel groups and they both have id="userPanel".

          • 2. Re: duplicate Id problem
            nitm

            right, im aware of that..
            BUT only one of them should be rendered, since the first one is rendered only if identity.loggedIn while the second if not identity.loggedIn and clearly identity.loggedIn can not be both true and false.
            is this the wrong the way to do this?  how else am i supposed to create a div which has a different set of elements based on if the user is logged in or not?


            thanks, nitzan;

            • 3. Re: duplicate Id problem
              clerum

              I'm pretty sure that it has to parse the entire page before deciding if it's rendered or not.

              • 4. Re: duplicate Id problem

                Exactly.

                • 5. Re: duplicate Id problem

                  nitzan tomer wrote on May 01, 2009 09:41:


                  right, im aware of that..
                  BUT only one of them should be rendered, since the first one is rendered only if identity.loggedIn while the second if not identity.loggedIn and clearly identity.loggedIn can not be both true and false.
                  is this the wrong the way to do this?  how else am i supposed to create a div which has a different set of elements based on if the user is logged in or not?



                  You mean like this?:

                  <h:panelGroup layout="block" id="userPanel" >
                  
                  <ui:fragment rendered="#{identity.loggedIn}">
                          #{identity.username} [<a href="#" onclick="return false;">Log Out</a>|<a href="#" onclick="return false;">Profile</a><a href="#">Settings</a>]
                  </h:panelGroup>
                  </ui:fragment> 
                  
                  <ui:fragment rendered="#{not identity.loggedIn}">
                          Guest [<a href="#" onclick="page.showAuthenticationForms(); return false;">Log In / Register</a>]
                  </ui:fragment> 
                  </h:panelGroup>
                  



                  or like this?:


                  <h:panelGroup layout="block" id="userPanel" >
                  
                  <c:if test="#{identity.loggedIn}">
                          #{identity.username} [<a href="#" onclick="return false;">Log Out</a>|<a href="#" onclick="return false;">Profile</a><a href="#">Settings</a>]
                  </c:if>
                  </ui:fragment> 
                  
                  <c:if test="#{not identity.loggedIn}">
                          Guest [<a href="#" onclick="page.showAuthenticationForms(); return false;">Log In / Register</a>]
                  </c:if> 
                  </h:panelGroup>
                  



                  The difference between c:if and ui:fragment is like the difference between c:forEach and ui:repeat.




                  thanks, nitzan;


                  Click HELP for text formatting instructions. Then edit this text and check the preview.

                  • 6. Re: duplicate Id problem
                    nitm

                    excellent!
                    thanks a lot for your help


                    nitzan;