Gonçalo Manuel Cruchinho created MYFACES-3853:
-------------------------------------------------

             Summary: ui:include not working inside c:forEach
                 Key: MYFACES-3853
                 URL: https://issues.apache.org/jira/browse/MYFACES-3853
             Project: MyFaces Core
          Issue Type: Bug
    Affects Versions: 2.2.0
            Reporter: Gonçalo Manuel Cruchinho
            Priority: Critical


Using ui:include inside a c:forEach cases a duplicate id error. This only 
happens if there is at least a second element to iterate.

The exception is the following: java.lang.IllegalStateException: Client-id : 
<clientId> is duplicated in the faces tree.

Below there's an example of a test case that replicates the problem.

Test Case

Myfaces22ForEach.java

@ManagedBean(name = "myfaces22foreach")
@SessionScoped
public class Myfaces22ForEach {

        private List<String> pageList;

        private String test;

        public List<String> getPageList() {
                if (pageList == null) {
                        pageList = new ArrayList<String>();
                        pageList.add("page1.xhtml");
                        pageList.add("page2.xhtml");
                }
                return pageList;
        }
        public void setPageList(List<String> pageList) {
                this.pageList = pageList;
        }

        public String getTest() {
                return test;
        }
        public void setTest(String test) {
                this.test = test;
        }
}

myfaces22foreach.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html
        xmlns="http://www.w3.org/1999/xhtml";
        xmlns:h="http://java.sun.com/jsf/html";
        xmlns:c="http://java.sun.com/jsp/jstl/core";
        xmlns:ui="http://java.sun.com/jsf/facelets";>
        
        <h:head>
            <title>Myfaces 2.2 | forEach Test</title>
        </h:head>
        <h:body>
                <h:form>
                        <table>
                                <c:forEach items="#{myfaces22foreach.pageList}" 
var="page">
                                        <tr>
                                                <td>
                                                        <ui:include 
src="#{page}" />
                                                </td>
                                        </tr>
                                </c:forEach>
                        </table>
                </h:form>
        </h:body>
</html>

page1.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<ui:composition
        xmlns="http://www.w3.org/1999/xhtml";
        xmlns:h="http://java.sun.com/jsf/html";
        xmlns:ui="http://java.sun.com/jsf/facelets";>
        
        <h:outputText value="Test" />
        
</ui:composition>

page2.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<ui:composition
        xmlns="http://www.w3.org/1999/xhtml";
        xmlns:h="http://java.sun.com/jsf/html";
        xmlns:ui="http://java.sun.com/jsf/facelets";>
        
        <h:inputText value="#{myfaces22foreach.page}" />
        
</ui:composition>



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to