4 Replies Latest reply on Aug 2, 2007 5:58 AM by Pete Muir

    c:forEach and h:column

    Francis LIMOUSY Newbie

      Hello,

      I know it's not directly a Seam issue but I saw this ticket on JIRA and tried to make it work here.
      We were using a lot t:columns before migrating to Seam and now we're looking for a replacement, but it looks like we're not the first ones (http://jira.jboss.com/jira/browse/JBSEAM-910).

      So we must use c:forEach instead of ui:repeat but, in my test, the first column only is displayed.
      After debugging, the rowIndex of the dataModel seems to iterate fine but starts at -1 (at object creation I guess).

      Does anyone have a working code snipplet ? Maybe Pete Muir who tested that on the JIRA ?

      Thanks for any help.

        • 1. Re: c:forEach and h:column
          Francis LIMOUSY Newbie

          Now I have an error regarding the usage of DataModel:

          <c:forEach items="#{TestCrossDataTable.boiteNoireSimple.columnDataModel}"> Must evaluate to a Collection, Map, Array, or null.
          


          I cannot use a DataModel in a JSTL Tag ? (Well, sounds normal as a matter of fact ...)

          How it is suppose to iterate over the page ?
          In my plain old JSF/Myfaces project, the iteration process was made using isRowAvailable() and getRowData() to get the correct Cell (Line X Column) ...


          • 2. Re: c:forEach and h:column
            Francis LIMOUSY Newbie

            Ok, after using a Datamodel for the lines and a List for the columns, I finally managed to get this (half-)working.

            To get the correct Cell, containing my object, I :

            - iterate over lines using isRowAvailable() and getRowData()

            - iterate over the columns using an int going from 0 to myList.size()

            in a method named getCellValue() in my backing bean.

            This works pretty well If I fetch only one time the cell content (the column counter is incremented one time per cell).
            But If need to fetch multiple times the cell (it's an object containing the value, a boolean for rendering, etc ...) then it doesn't work.
            My column counter is incremented bean-side, so it doesn't care if I'm still on the same cell jsf-side ...

            When I was using DataModel for both lines and columns (JSP/Myfaces project, before Seam), isRowAvailable() and getRowData() used to handle increment neatly.

            Am I missing something here ?

            BTW, a portion of code from my backing bean

             public CELLOBJECT getCellValue(){
             DataModel lineDataModel = getLineDataModel();
             if (lineDataModel.isRowAvailable()) {
             Line line = (Line) lineDataModel.getRowData();
            
             if(compteurColonnes >= this.getColumnList().size()){
             compteurColonnes = 0;
             }
            
             for (Iterator<Cell<CELLOBJECT>> it = line.getCellList().iterator(); it.hasNext();) {
             Cell<CELLOBJECT> cell = it.next();
             if (cell.getColumnId() == compteurColonnes) {
             System.out.println("[ " + cell.getLineId() + " , " + cell.getColumnId() + " ] = " + cell.getCellValue().toString());
             compteurColonnes++;
             return cell.getCellValue();
             }
             }
            
             }
             return cellValue;
             }
            


            • 3. Re: c:forEach and h:column
              Francis LIMOUSY Newbie

              Ok, I'm upping a little this post cause this still doesn't work (arg!).
              I tried a simplier solution using the [] operator in the JSF.
              It looks like this :

               <h:dataTable value="#{TestCrossDataTable.boiteNoireSimple.lineDataModel}" var="lineSimple">
              
               <c:forEach items="#{TestCrossDataTable.boiteNoireSimple.columnDataModel.wrappedData}" var="columnSimple">
               <h:column>
              
               <f:facet name="header">
               <h:outputText value="#{columnSimple.columnDesignation}" />
               </f:facet>
              
              
              
               <h:inputText value="#{lineSimple.cellList[columnSimple.columnId].cellValue.jourSaisieValeur}"
               converter="javax.faces.Double">
               </h:inputText>
              
              
               </h:column>
               </c:forEach>
              
               </h:dataTable>
              


              I thought it could save my life but no :/
              I can iterate normally over cells, and make my dynamic columns, but I still can access ONE TIME only the cell.
              And I need to access multiple times the object in the cell ...

              • 4. Re: c:forEach and h:column
                Pete Muir Master

                Yes, that last code snippet looks correct. Can you explain in more detail whats going wrong with it.