11 Replies Latest reply on Mar 18, 2009 8:44 AM by tmahesh1983

    How to avoid duplicate id in component

      Hi
      I need to design datatable with dynamic number of columns, so i was try to design <rich:datatable> with <rich:columns> tag, that produces
      javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.IllegalStateException: Duplicate component id

      I was come across multiple posts they suggest to avoid duplicate id exception assign id for every component. I have tried like that even problem comes. I have enclosed page code and stack trace with this post.

      <rich:dataTable id="sampleDataTable" value="#{Sample.dataList}" var="record">
      <f:facet name="header">
      <rich:columnGroup id="headerColumnGroup">
      <rich:column id="nameColumnHeader" rowspan="2">
      <h:outputText value="Name"/>
      </rich:column>
      <rich:column id="itemsColumnHeader" colspan="3">
      <h:outputText value="Items" />
      </rich:column>
      <rich:column id="firstItemHeader" breakBefore="true">
      <h:outputText value="Item-1" />
      </rich:column>
      <rich:columns id="itemColumns" columns="2">
      <h:outputText value="Item"/>
      </rich:columns>
      </rich:columnGroup>
      </f:facet>
      <rich:column id="nameColumn">
      <h:outputText value="#{record.name}"/>
      </rich:column>
      <rich:columns id="selectItem" columns="3">
      <h:selectBooleanCheckbox id="categoryCheckBox"/>
      </rich:columns>
      </rich:dataTable>

      Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
      com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:473)
      com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:141)
      org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
      org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:189)
      com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
      com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
      org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:154)
      org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
      org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
      org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
      org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)

      javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.IllegalStateException: Duplicate component id: 'sampleForm:sampleDataTable:rf0', first used in tag: 'org.richfaces.taglib.ColumnsTag'
      +id: j_id_jsp_935888301_0

        • 1. Re: How to avoid duplicate id in component

          Try to set only the IDs you need for referencing. Delete all others.

          • 2. Re: How to avoid duplicate id in component

            i was try like that...same problem occurs

            • 3. Re: How to avoid duplicate id in component

              Here are some more suggestions:

              1.) Search in this forum, because we had this issues a lot of times in the past.
              2.) If possible try it without myfaces.
              3.) Post your environment data so it is easier for a RF team member to post some help.

              • 4. Re: How to avoid duplicate id in component
                ronanker

                i remember i had this issue before but sorry can't remember what it was...

                just looking at my code, it's like yours but with a columnGroup more :

                <rich:dataTable id="sampleDataTable" value="#{Sample.dataList}" var="record">
                 <f:facet name="header">
                 <rich:columnGroup id="headerColumnGroup">
                 <rich:column id="nameColumnHeader" rowspan="2">
                 <h:outputText value="Name"/>
                 </rich:column>
                 <rich:column id="itemsColumnHeader" colspan="3">
                 <h:outputText value="Items" />
                 </rich:column>
                 <rich:column id="firstItemHeader" breakBefore="true">
                 <h:outputText value="Item-1" />
                 </rich:column>
                 <rich:columns id="itemColumns" columns="2">
                 <h:outputText value="Item"/>
                 </rich:columns>
                 </rich:columnGroup>
                 </f:facet>
                 <rich:columnGroup>
                 <rich:column id="nameColumn">
                 <h:outputText value="#{record.name}"/>
                 </rich:column>
                 <rich:columns id="selectItem" columns="3">
                 <h:selectBooleanCheckbox id="categoryCheckBox"/>
                 </rich:columns>
                 </rich:columnGroup>
                </rich:dataTable>


                • 5. Re: How to avoid duplicate id in component

                  Hi

                  I try with <rich:columnGroup>, still same problem continues. whenever i remove one <rich:columns> from data table it works. for example the following code works well. but i don't want like this. I want to add column dynamically.


                  <rich:dataTable id="sampleDataTable" value="#{Sample.dataList}" var="record">
                  <f:facet name="header">
                  <rich:columnGroup id="headerColumnGroup">
                  <rich:column id="nameColumnHeader" rowspan="2">
                  <h:outputText value="Name"/>
                  </rich:column>
                  <rich:column id="itemsColumnHeader" colspan="3">
                  <h:outputText value="Items" />
                  </rich:column>
                  <rich:column id="firstItemHeader" breakBefore="true">
                  <h:outputText value="Item-1" />
                  </rich:column>
                  <rich:column id="secondItemHeader">
                  <h:outputText value="Item-2"/>
                  </rich:column>
                  <rich:column id="thirdItemHeader">
                  <h:outputText value="Item-3"/>
                  </rich:column>
                  </rich:columnGroup>
                  </f:facet>
                  <rich:column id="nameColumn">
                  <h:outputText value="#{record.name}"/>
                  </rich:column>
                  <rich:columns id="selectItem" columns="3">
                  <h:selectBooleanCheckbox id="categoryCheckBox"/>
                  </rich:columns>
                  </rich:dataTable>

                  • 6. Re: How to avoid duplicate id in component
                    ronanker

                    your right.

                    The following code should work:

                    <rich:dataTable id="sampleDataTable" value="#{Sample.dataList}" var="record">
                     <f:facet name="header">
                     <f:subview id="header">
                     <rich:columns ...
                     </f:subview>
                     </f:facet>
                     <rich:columns ...
                    


                    • 7. Re: How to avoid duplicate id in component
                      nbelaevski

                      Please try 3.3.1-snapshot

                      • 8. Re: How to avoid duplicate id in component

                        Hi,

                        I am wondering about the hierarchy of the assigned component ids.

                        Assuming a component tree like this


                        +id: j_id_id18
                         type: org.ajax4jsf.component.AjaxViewRoot@162190
                         +id: sampleDataTable
                         type: org.richfaces.component.html.HtmlDataTable@f5a010
                         +id: ColGroup_1
                         type: org.richfaces.component.html.HtmlColumnGroup@1dfb87a
                         +id: rf0
                         type: org.richfaces.component.html.HtmlColumn@c8756c
                         +id: rf1
                         type: org.richfaces.component.html.HtmlColumn@0982fe
                         +id: ColGroup_2
                         type: org.richfaces.component.html.HtmlColumnGroup@1dfb87a
                         +id: rf0
                         type: org.richfaces.component.html.HtmlColumn@c8756c
                         +id: rf1
                         type: org.richfaces.component.html.HtmlColumn@0982fe



                        Shouldn't the full component ids be
                        'sampleDataTable:ColGroup_1:rf0'

                        and
                        'sampleDataTable:ColGroup_2:rf0'

                        according to the hierarchy given by the indentation of the component tree?


                        Because the exception leaves out the component group id?

                        IllegalStateException: Duplicate component id: 'sampleForm:sampleDataTable:rf0'



                        Why is ComponentGroup id ignored?

                        Actually "rf0" is not a unique id anyway, so why does RF not assign unique ids in the first place when user has not assigned explicit ids?

                        Thanks for your help.


                            • 9. Re: How to avoid duplicate id in component


                              3.3.1 snapshot did the trick, at least in my case.

                              Thanks a lot, great work!

                              • 10. Re: How to avoid duplicate id in component

                                Hi Friends,
                                Thanks to all, I found answer for this problem

                                The following thread has solution for this problem

                                http://forums.sun.com/thread.jspa?messageID=10646384

                                • 11. Re: How to avoid duplicate id in component

                                  Hi
                                  Thanks to all

                                  I found answer for this problem

                                  please see the following thread for solution

                                  http://forums.sun.com/thread.jspa?messageID=10646384