You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Helmut Swaczinna <sw...@wlp-systems.de> on 2007/05/02 13:15:13 UTC

Re: [Tobago] c:forEach doesn't work anymore with myFaces 1.1.5

Please help!

Regards
Helmut
  ----- Original Message ----- 
  From: Helmut Swaczinna 
  To: MyFaces Discussion 
  Sent: Friday, April 27, 2007 6:06 PM
  Subject: Re: [Tobago] c:forEach doesn't work anymore with myFaces 1.1.5


  Hi,

  I was able to create a (not really) simple example to reproduce the described behavior but with two differences: First, I
  get only the second exception and second, the exception is also thrown with myFaces 1.1.4. With a really simple
  example there's no problem. But life isn't such simple like tests and demos...


  Here comes the source code:

  test.jsp

  <%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" 
  %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" 
  %><%@ page contentType="text/html;charset=UTF-8" language="java" 
  %><%@ page pageEncoding="UTF-8" 
  %><f:view
   ><tc:page id="testPage1" width="300px" height="200px">
      <tc:button label="Foreach test" 
        action="#{controller.foreachTest}" />      
    </tc:page>
  </f:view>

  foreach.jsp

  <%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" 
  %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" 
  %><%@ page contentType="text/html;charset=UTF-8" language="java" 
  %><%@ page pageEncoding="UTF-8" 
  %><f:view
   ><tc:page id="testPage2" width="300px" height="200px">
      <jsp:include page="foreach1.jsp"/>
    </tc:page>
  </f:view>

  foreach1.jsp

  <%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" 
  %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" 
  %><%@ page contentType="text/html;charset=UTF-8" language="java" 
  %><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" 
  %><%@ page pageEncoding="UTF-8" 
  %><f:subview id="foreachView"
   ><tc:panel>
      <f:facet name="layout">
        <tc:gridLayout rows="fixed;*"/>
      </f:facet>
      <%@ include file="foreach2.jsp" %>
      <tc:cell/>
    </tc:panel>
  </f:subview>

  foreach2.jsp

  <%@ page pageEncoding="UTF-8" %>
    <tc:panel id="foreachPanel">

      <f:facet name="layout">
        <tc:gridLayout
          rows="fixed;#{controller.layoutRows}fixed"
          columns="1*;1*"/>
      </f:facet>
      
      <tc:label value="Column 1"/>
      <tc:label value="Column 2"/>
      
      <c:forEach items="${controller.list}" 
        varStatus="status" begin="0">
        <tc:panel id="panel_${status.index}">
          <f:facet name="layout">
            <tc:gridLayout cellspacing="0" 
              rows="fixed"
              columns="1*;1*"/>
          </f:facet>            
          <tc:in id="column1_${status.index}_1" 
            rendered="true"
            value="#{controller.list[${status.index}].column1}"/>
          <tc:in id="column1_${status.index}_2" 
            rendered="false"
            value="#{controller.list[${status.index}].column1}"/>
        </tc:panel>
        <tc:in id="column2_${status.index}" 
          value="#{controller.list[${status.index}].column2}"/>
      </c:forEach>

      <tc:button id="insertButton" 
        label="insert"
        action="#{controller.insert}"/>
      <tc:button id="deleteButton" 
        label="delete"
        action="#{controller.delete}"/>
      
    </tc:panel>

  Controller.java

  package de.wlps.test.tobago;

  import java.util.ArrayList;
  import java.util.List;

  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;

  public class Controller {
    
    private static final Log LOG = LogFactory.getLog(Controller.class);

    private List<Row> list = new ArrayList<Row>();

    public Controller() {
      LOG.debug("Controller");
      list.add(new Row("Value 1/1", "Value 2/1"));
    }
    
    public String foreachTest() {
      LOG.debug("foreachTest");
      return "foreach";
    }

    public String insert() {
      LOG.debug("insert");
      list.add(new Row("Value 1/" + (list.size()+1), "Value 2/" + (list.size()+1)));
      return "foreach";
    }

    public String delete() {
      LOG.debug("delete");
      if (list.size() > 0) {
        list.remove(list.size() - 1);
      }
      return "foreach";
    }
    
    public List<Row> getList() {
      LOG.debug("getList");
      return list;
    }
    
    public String getLayoutRows() {
      LOG.debug("getLayoutRows");
      String rows = "";
      for (int i = 0; i < list.size(); i++) {
        rows += "fixed;";
      }
      return rows;
    }
    
    public class Row {
      
      private String column1;
      private String column2;
      
      
      public Row(String column1, String column2) {
        super();
        this.column1 = column1;
        this.column2 = column2;
      }
      
      public String getColumn1() {
        return column1;
      }
      
      public void setColumn1(String column1) {
        this.column1 = column1;
      }
      
      public String getColumn2() {
        return column2;
      }
      
      public void setColumn2(String column2) {
        this.column2 = column2;
      }
      
    }
  }

  faces-config.xml

  <faces-config>

    <application>
      <locale-config>
        <default-locale>en</default-locale>
        <supported-locale>de</supported-locale>
      </locale-config>
    </application>
    
    <managed-bean>
      <managed-bean-name>controller</managed-bean-name>
      <managed-bean-class>de.wlps.test.tobago.Controller</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

    <navigation-rule>
      <from-view-id>/test.jsp</from-view-id>
      <navigation-case>
      <from-outcome>foreach</from-outcome>
      <to-view-id>/foreach.jsp</to-view-id>
      </navigation-case>
    </navigation-rule>

  </faces-config>


  Start with test.jsp, press the "Foreach test" button and then press the "insert" button. This should insert a new row
  in the list. But you will get this exception:

  2007-04-27 17:47:07 http-8080-Processor23 ERROR - org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/tobago-test].[jsp]:704 - Servlet.ser
  vice() for servlet jsp threw exception
  java.lang.IllegalStateException: Client-id : _idJsp6 is duplicated in the faces tree. Component : testPage2:foreachView:_idJsp6, path: {Component-Path
   : [Class: org.apache.myfaces.tobago.component.UIViewRoot,ViewId: /foreach.jsp][Class: org.apache.myfaces.tobago.component.UIPage,Id: testPage2][Class
  : javax.faces.component.UINamingContainer,Id: foreachView][Class: org.apache.myfaces.tobago.component.UIPanel,Id: _idJsp0][Class: org.apache.myfaces.t
  obago.component.UICell,Id: _idJsp6]}
          at org.apache.myfaces.application.jsp.JspStateManagerImpl.checkForDuplicateIds(JspStateManagerImpl.java:350)


  Because the duplicate id is a generated id there must be a problem with the id generator or with the foreach tag.
  If you make the example simplier, for example remove the panel in the foreach loop or remove one of the includes,
  the problem disappers.

  Maybe this problem has nothing to do with Tobago. If so, please forward it to the myFaces developers.

  Regards
  Helmut


    ----- Original Message ----- 
    From: Helmut Swaczinna 
    To: users@myfaces.apache.org 
    Sent: Wednesday, April 25, 2007 3:55 PM
    Subject: [Tobago] c:forEach doesn't work anymore with myFaces 1.1.5


    Hi,

    I use the c:forEach tag in some pages and it worked with myFaces 1.1.4. Now I had to switch to myFaces 1.1.5
    (because there was an other bug with Tobago and myFaces 1.1.4) and it doesn't work anymore. When the page is
    displayed for the first time everything is ok. But when the number of rows in the underlying list changes and the
    page is redisplayed I always get an exception:

    java.lang.ArrayIndexOutOfBoundsException: 5
            at org.apache.myfaces.tobago.util.LayoutInfo.getSpaceForColumn(LayoutInfo.java:206)
            at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.setColumnWidths(GridLayoutRenderer.java:706)
            at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.layoutWidth(GridLayoutRenderer.java:543)
            at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.layoutEnd(GridLayoutRenderer.java:493)
            at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent(GridLayoutRenderer.java:233)

    or

    java.lang.IllegalStateException: Client-id : _idJsp350 is duplicated in the faces tree. Component : editPage:detailView:anteileView2:_idJsp350, path:
    {Component-Path : [Class: org.apache.myfaces.tobago.component.UIViewRoot,ViewId: /edit.jsp][Class: org.apache.myfaces.tobago.component.UIPage,Id: edit
    Page][Class: org.apache.myfaces.tobago.component.UIPanel,Id: panel][Class: org.apache.myfaces.tobago.component.UIPanel,Id: mainPanel][Class: org.apach
    e.myfaces.tobago.component.UICell,Id: _idJsp86][Class: javax.faces.component.UINamingContainer,Id: detailView][Class: org.apache.myfaces.tobago.compon
    ent.UIPanel,Id: panel][Class: org.apache.myfaces.tobago.component.UITabGroup,Id: _idJsp87][Class: org.apache.myfaces.tobago.component.UIPanel,Id: ante
    ileTab][Class: javax.faces.component.UINamingContainer,Id: anteileView2][Class: org.apache.myfaces.tobago.component.UIPanel,Id: panel][Class: org.apac
    he.myfaces.tobago.component.UIPanel,Id: copartnerPanel][Class: org.apache.myfaces.tobago.component.UICell,Id: _idJsp349][Class: org.apache.myfaces.tob
    ago.component.UIPanel,Id: _idJsp350]}
            at org.apache.myfaces.application.jsp.JspStateManagerImpl.checkForDuplicateIds(JspStateManagerImpl.java:329)


    Do I have to change my code when I switch to myFaces 1.1.5? Do I need a new jstl version?
    I'm using jstl 1.1.0 and Tobago 1.0.11 snapshot from a week ago.

    Regards
    Helmut



Re: [Tobago] c:forEach doesn't work anymore with myFaces 1.1.5

Posted by Simon Kitching <si...@rhe.co.nz>.
The c:forEach tag has never been supported by JSF1.1 with JSP.
If it worked for you before, then that was just a coincidence.

You need to get rid of the c:forEach tag. I don't know tobago; maybe it 
has its own equivalent of "forEach". If it doesn't then I think the 
Tomahawk t:dataList tag should work ok with it.

Regards,

Simon

Helmut Swaczinna wrote:
> Please help!
>  
> Regards
> Helmut
> 
>     ----- Original Message -----
>     *From:* Helmut Swaczinna <ma...@wlp-systems.de>
>     *To:* MyFaces Discussion <ma...@myfaces.apache.org>
>     *Sent:* Friday, April 27, 2007 6:06 PM
>     *Subject:* Re: [Tobago] c:forEach doesn't work anymore with myFaces
>     1.1.5
> 
>     Hi,
>      
>     I was able to create a (not really) simple example to reproduce the
>     described behavior but with two differences: First, I
>     get only the second exception and second, the exception is also
>     thrown with myFaces 1.1.4. With a really simple
>     example there's no problem. But life isn't such simple like tests
>     and demos...
>      
>      
>     Here comes the source code:
>      
>     test.jsp
>      
>     <%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc"
>     %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"
>     %><%@ page contentType="text/html;charset=UTF-8" language="java"
>     %><%@ page pageEncoding="UTF-8"
>     %><f:view
>      ><tc:page id="testPage1" width="300px" height="200px">
>         <tc:button label="Foreach test"
>           action="#{controller.foreachTest}" />     
>       </tc:page>
>     </f:view>
>      
>     foreach.jsp
>      
>     <%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc"
>     %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"
>     %><%@ page contentType="text/html;charset=UTF-8" language="java"
>     %><%@ page pageEncoding="UTF-8"
>     %><f:view
>      ><tc:page id="testPage2" width="300px" height="200px">
>         <jsp:include page="foreach1.jsp"/>
>       </tc:page>
>     </f:view>
>      
>     foreach1.jsp
>      
>     <%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc"
>     %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"
>     %><%@ page contentType="text/html;charset=UTF-8" language="java"
>     %><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"
>     %><%@ page pageEncoding="UTF-8"
>     %><f:subview id="foreachView"
>      ><tc:panel>
>         <f:facet name="layout">
>           <tc:gridLayout rows="fixed;*"/>
>         </f:facet>
>         <%@ include file="foreach2.jsp" %>
>         <tc:cell/>
>       </tc:panel>
>     </f:subview>
>      
>     foreach2.jsp
>      
>     <%@ page pageEncoding="UTF-8" %>
>       <tc:panel id="foreachPanel">
>      
>         <f:facet name="layout">
>           <tc:gridLayout
>             rows="fixed;#{controller.layoutRows}fixed"
>             columns="1*;1*"/>
>         </f:facet>
>        
>         <tc:label value="Column 1"/>
>         <tc:label value="Column 2"/>
>        
>         <c:forEach items="${controller.list}"
>           varStatus="status" begin="0">
>           <tc:panel id="panel_${status.index}">
>             <f:facet name="layout">
>               <tc:gridLayout cellspacing="0"
>                 rows="fixed"
>                 columns="1*;1*"/>
>             </f:facet>           
>             <tc:in id="column1_${status.index}_1"
>               rendered="true"
>               value="#{controller.list[${status.index}].column1}"/>
>             <tc:in id="column1_${status.index}_2"
>               rendered="false"
>               value="#{controller.list[${status.index}].column1}"/>
>           </tc:panel>
>           <tc:in id="column2_${status.index}"
>             value="#{controller.list[${status.index}].column2}"/>
>         </c:forEach>
>      
>         <tc:button id="insertButton"
>           label="insert"
>           action="#{controller.insert}"/>
>         <tc:button id="deleteButton"
>           label="delete"
>           action="#{controller.delete}"/>
>        
>       </tc:panel>
>     Controller.java
>      
>     package de.wlps.test.tobago;
>      
>     import java.util.ArrayList;
>     import java.util.List;
>      
>     import org.apache.commons.logging.Log;
>     import org.apache.commons.logging.LogFactory;
>      
>     public class Controller {
>      
>       private static final Log LOG = LogFactory.getLog(Controller.class);
>      
>       private List<Row> list = new ArrayList<Row>();
>      
>       public Controller() {
>         LOG.debug("Controller");
>         list.add(new Row("Value 1/1", "Value 2/1"));
>       }
>      
>       public String foreachTest() {
>         LOG.debug("foreachTest");
>         return "foreach";
>       }
>      
>       public String insert() {
>         LOG.debug("insert");
>         list.add(new Row("Value 1/" + (list.size()+1), "Value 2/" +
>     (list.size()+1)));
>         return "foreach";
>       }
>      
>       public String delete() {
>         LOG.debug("delete");
>         if (list.size() > 0) {
>           list.remove(list.size() - 1);
>         }
>         return "foreach";
>       }
>      
>       public List<Row> getList() {
>         LOG.debug("getList");
>         return list;
>       }
>      
>       public String getLayoutRows() {
>         LOG.debug("getLayoutRows");
>         String rows = "";
>         for (int i = 0; i < list.size(); i++) {
>           rows += "fixed;";
>         }
>         return rows;
>       }
>      
>       public class Row {
>        
>         private String column1;
>         private String column2;
>        
>        
>         public Row(String column1, String column2) {
>           super();
>           this.column1 = column1;
>           this.column2 = column2;
>         }
>        
>         public String getColumn1() {
>           return column1;
>         }
>        
>         public void setColumn1(String column1) {
>           this.column1 = column1;
>         }
>        
>         public String getColumn2() {
>           return column2;
>         }
>        
>         public void setColumn2(String column2) {
>           this.column2 = column2;
>         }
>        
>       }
>     }
>     faces-config.xml
>      
>     <faces-config>
>      
>       <application>
>         <locale-config>
>           <default-locale>en</default-locale>
>           <supported-locale>de</supported-locale>
>         </locale-config>
>       </application>
>      
>       <managed-bean>
>         <managed-bean-name>controller</managed-bean-name>
>        
>     <managed-bean-class>de.wlps.test.tobago.Controller</managed-bean-class>
>         <managed-bean-scope>session</managed-bean-scope>
>       </managed-bean>
>      
>       <navigation-rule>
>         <from-view-id>/test.jsp</from-view-id>
>         <navigation-case>
>         <from-outcome>foreach</from-outcome>
>         <to-view-id>/foreach.jsp</to-view-id>
>         </navigation-case>
>       </navigation-rule>
>     </faces-config>
>      
>     Start with test.jsp, press the "Foreach test" button and then press
>     the "insert" button. This should insert a new row
>     in the list. But you will get this exception:
>      
>     2007-04-27 17:47:07 http-8080-Processor23 ERROR -
>     org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/tobago-test].[jsp]:704
>     - Servlet.ser
>     vice() for servlet jsp threw exception
>     java.lang.IllegalStateException: Client-id : _idJsp6 is duplicated
>     in the faces tree. Component : testPage2:foreachView:_idJsp6, path:
>     {Component-Path
>      : [Class: org.apache.myfaces.tobago.component.UIViewRoot,ViewId:
>     /foreach.jsp][Class: org.apache.myfaces.tobago.component.UIPage,Id:
>     testPage2][Class
>     : javax.faces.component.UINamingContainer,Id: foreachView][Class:
>     org.apache.myfaces.tobago.component.UIPanel,Id: _idJsp0][Class:
>     org.apache.myfaces.t
>     obago.component.UICell,Id: _idJsp6]}
>             at
>     org.apache.myfaces.application.jsp.JspStateManagerImpl.checkForDuplicateIds(JspStateManagerImpl.java:350)
>      
>      
>     Because the duplicate id is a generated id there must be a problem
>     with the id generator or with the foreach tag.
>     If you make the example simplier, for example remove the panel in
>     the foreach loop or remove one of the includes,
>     the problem disappers.
>      
>     Maybe this problem has nothing to do with Tobago. If so, please
>     forward it to the myFaces developers.
>      
>     Regards
>     Helmut
>      
>      
> 
>         ----- Original Message -----
>         *From:* Helmut Swaczinna <ma...@wlp-systems.de>
>         *To:* users@myfaces.apache.org <ma...@myfaces.apache.org>
>         *Sent:* Wednesday, April 25, 2007 3:55 PM
>         *Subject:* [Tobago] c:forEach doesn't work anymore with myFaces
>         1.1.5
> 
>         Hi,
>          
>         I use the c:forEach tag in some pages and it worked with myFaces
>         1.1.4. Now I had to switch to myFaces 1.1.5
>         (because there was an other bug with Tobago and myFaces 1.1.4)
>         and it doesn't work anymore. When the page is
>         displayed for the first time everything is ok. But when the
>         number of rows in the underlying list changes and the
>         page is redisplayed I always get an exception:
>          
>         java.lang.ArrayIndexOutOfBoundsException: 5
>                 at
>         org.apache.myfaces.tobago.util.LayoutInfo.getSpaceForColumn(LayoutInfo.java:206)
>                 at
>         org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.setColumnWidths(GridLayoutRenderer.java:706)
>                 at
>         org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.layoutWidth(GridLayoutRenderer.java:543)
>                 at
>         org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.layoutEnd(GridLayoutRenderer.java:493)
>                 at
>         org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent(GridLayoutRenderer.java:233)
>          
>         or
>          
>         java.lang.IllegalStateException: Client-id : _idJsp350 is
>         duplicated in the faces tree. Component :
>         editPage:detailView:anteileView2:_idJsp350, path:
>         {Component-Path : [Class:
>         org.apache.myfaces.tobago.component.UIViewRoot,ViewId:
>         /edit.jsp][Class: org.apache.myfaces.tobago.component.UIPage,Id:
>         edit
>         Page][Class: org.apache.myfaces.tobago.component.UIPanel,Id:
>         panel][Class: org.apache.myfaces.tobago.component.UIPanel,Id:
>         mainPanel][Class: org.apach
>         e.myfaces.tobago.component.UICell,Id: _idJsp86][Class:
>         javax.faces.component.UINamingContainer,Id: detailView][Class:
>         org.apache.myfaces.tobago.compon
>         ent.UIPanel,Id: panel][Class:
>         org.apache.myfaces.tobago.component.UITabGroup,Id:
>         _idJsp87][Class: org.apache.myfaces.tobago.component.UIPanel,Id:
>         ante
>         ileTab][Class: javax.faces.component.UINamingContainer,Id:
>         anteileView2][Class:
>         org.apache.myfaces.tobago.component.UIPanel,Id: panel][Class:
>         org.apac
>         he.myfaces.tobago.component.UIPanel,Id: copartnerPanel][Class:
>         org.apache.myfaces.tobago.component.UICell,Id: _idJsp349][Class:
>         org.apache.myfaces.tob
>         ago.component.UIPanel,Id: _idJsp350]}
>                 at
>         org.apache.myfaces.application.jsp.JspStateManagerImpl.checkForDuplicateIds(JspStateManagerImpl.java:329)
>          
>          
>         Do I have to change my code when I switch to myFaces 1.1.5? Do I
>         need a new jstl version?
>         I'm using jstl 1.1.0 and Tobago 1.0.11 snapshot from a week ago.
>          
>         Regards
>         Helmut
>          
>          
>