facelets
  1. facelets
  2. FACELETS-369

"Component ID has already been found in the view" thrown when using composite components with <c:if> or <c:forEach>

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.15
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      JSF 2.0 RI

      Description

      There seems to be a problem with the algorithm that assigns tag ids. Say we have the following code:

      "example.xhtml"
      	<h:form id="form">
      		<c:if test="#{Bean.clicked}">
      			<ns:compositeComponent id="aa"/>
      		</c:if>
      		<ns:compositeComponent id="bb"/>
      		<h:commandLink value="Click" action="#{Bean.click}" />
      	</h:form>
      

      where ns is some namespace and compositeComponent is a component defined in its own file:

      "compositeComponent.xhtml"
              <h:panelGroup id="#{id}" xmlns:h="http://java.sun.com/jsf/html"/>
      

      The implementation of Bean (session scoped in my case):

      "Bean.java"
      	public class Bean {
      		private boolean clicked = false;
      		
      		public boolean isClicked() {
      			return clicked;
      		}
      		
      		public void click() {
      			clicked = true;
      		}
      	}
      

      After clicking on the command link the exception is thrown:
      Component ID form:bb has already been found in the view.

      The problem is that during the process of building view after the click, the generated id for the first <h:panelGroup> component (inside <c:if>) is exactly the same as it was for the second <h:panelGroup> during the first tree building process. This way during the second tree building process the first <h:panelGroup> component is found and the second (the one outside <c:if>) - was not found, therefore the second one is created and assigned JSF id "bb". This way we have two <h:panelGroup> components with id="bb"

        Activity

        Hide
        TomaszKurpios added a comment -

        When I wrote "component is found" I meant that ComponentSupport.findChildByTagId method inside ComponentHandler.apply method returned a non-empty result.

        Show
        TomaszKurpios added a comment - When I wrote "component is found" I meant that ComponentSupport.findChildByTagId method inside ComponentHandler.apply method returned a non-empty result.
        Hide
        piojas added a comment -

        I believe that this patch to DefaultFaceletContext fixes this problem. Could someone verify it please?

        Show
        piojas added a comment - I believe that this patch to DefaultFaceletContext fixes this problem. Could someone verify it please?

          People

          • Assignee:
            Unassigned
            Reporter:
            TomaszKurpios
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: