How to implement row numbering into h:dataTable

后端 未结 2 388
忘了有多久
忘了有多久 2021-01-06 05:28

I have this JSF table with pagination.




        
相关标签:
2条回答
  • 2021-01-06 06:15

    Im not sure I understand correctly. You just want the rows numbered?

    However, I don't think it's as easy as you might think it is. h:dataTable actually doesn't support this. And mixing h:dataTable and ui:repeat seems like the completely wrong way to do this (if I understand correctly).

    You could:

    • Use t:dataTable (from Tomahawk: http://myfaces.apache.org/tomahawk/index.html). There you can use the rowIndexVar Attribute, like so:

      <t:dataTable rowIndexVar="row" value="#{someBean.value}">  
          <h:column>  
              <h:outputText value="#{row + 1}"/>  
          </h:column>  
      </t:dataTable>
      
    • Alternativly, change your data model and provide the index inside there. Or use a wrapper class:

      public class DataWrapper{
          private int index;
          private Object model;
          // getter and setter
          ...
      }
      

      Then pass a list of DataWrapper to JSF, instead of your model directly. You need to set the index somewhere in your service layer first, of course.

    I hope this helps. Let me know if you need further assistance.

    0 讨论(0)
  • 2021-01-06 06:27

    Use UIData#getRowIndex().

    <h:dataTable binding="#{table}" ...>
        <h:column>
            #{table.rowIndex + SessionsController.firstRow + 1}
        </h:column>
        ...
    </h:dataTable>
    
    0 讨论(0)
提交回复
热议问题