Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 80603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:19:43+00:00 2026-05-10T21:19:43+00:00

In a JSF dataTable I want to display the row index next to the

  • 0

In a JSF dataTable I want to display the row index next to the rows… like:

Column A    Column B 1           xxx 2           yyy 

I thought that I could use an implicit el variable like #{rowIndex} but this is not working.

A solution I found is to create a binding for the data table and use the binding like:

<h:dataTable var='item' value='#{controller.items}' binding='#{controller.dataTable}'>     <h:column>#{controller.dataTable.rowIndex}</h:column>     <h:column>value</h:column> </h:dataTable> 

but this solution is complex and doesn’t work well when I have many nested dataTables in a page.

Any ideas on how to solve this in a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:19:43+00:00Added an answer on May 10, 2026 at 9:19 pm

    The existing solution does not strike me as a bad one. The rowIndex should work in nested tables so long as you’re referencing the model of the nested table.

        <h:dataTable border='1' value='#{nestedDataModel}' var='nested'>         <h:column>             <h:dataTable border='1' value='#{nested}' var='item'>                 <h:column>                     <h:outputText value='#{nested.rowIndex}' />                 </h:column>                 <h:column>                     <h:outputText value='#{item}' />                 </h:column>             </h:dataTable>         </h:column>     </h:dataTable> 

    Sample model:

    public class NestedDataModel extends DataModel implements Serializable {      private List<List<String>> nestedDataModel = populateModel();     private int index;      private List<List<String>> populateModel() {         List<List<String>> list = new ArrayList<List<String>>();         for(int x=0; x<3; x++) {             List<String> nestedTableData = new ArrayList<String>();             for(int y=0; y<3; y++) {                 nestedTableData.add('Foo x='+x+' y='+y);             }             list.add(nestedTableData);         }         return list;     }      @Override     public int getRowCount() {         return nestedDataModel.size();     }      @Override     public Object getRowData() {         List<String> list = nestedDataModel.get(index);         return new ListDataModel(list);     }      @Override     public int getRowIndex() {         return index;     }      @Override     public Object getWrappedData() {         return nestedDataModel;     }      @Override     public boolean isRowAvailable() {         return index >= 0 && index < nestedDataModel.size();     }      @Override     public void setRowIndex(int arg0) {         index = arg0;     }      @Override     public void setWrappedData(Object arg0) {         throw new UnsupportedOperationException();     }  } 

    Nesting dataTables should generally be avoided – if you’re not careful (e.g. make them children of a form), this can lead to a O(N^2) pass over the table children for each phase of the lifecycle on a submit (and there are 6 phases in the lifecycle).


    For something that is external to the model, you could use a simple counter in a managed bean:

    public class RowCounter implements Serializable {      private transient int row = 0;      public int getRow() {         return ++row;     }  } 

    Config:

    <managed-bean>     <managed-bean-name>rowCounter</managed-bean-name>     <managed-bean-class>tablerows.RowCounter</managed-bean-class>     <managed-bean-scope>request</managed-bean-scope> </managed-bean> 

    View:

    <f:view>     <h:dataTable border='1' value='#{tableDataBean.tableDataModel}'         var='rowBean'>         <h:column>             <h:outputText value='#{rowCounter.row}' />         </h:column>         <h:column>             <h:outputText value='#{rowBean}' />         </h:column>     </h:dataTable> </f:view> 

    This works because the bean is request-scope and bound to a read-only control outside a form. It would not work in a nested dataTable unless you wanted the row counter to be global to the view. But then, I’m not convinced that the row index should be a function of the view.

    For a nested dataTable, you would be better off providing the row index from the row bean. It gives you more control if you decide to do things like pagination over data sets too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSF datatable. I want to highlight the row when I select
I want to do some opertaions in the row of my JSF datatable, and
I saw datatable component in JSF and it typically renders as table row by
Let's consider that I want to extend an existing JSF component, such as the
I use Richfaces, Seam and JSF, and I want something like the following: and
I have a JSF 1.2 dataTable using ICEfaces 1.8. In one column, I would
How can i set row level rendering in datatable JSF. <h:dataTable styleClass=tablesub border=0 value=#{historyQuestBean.answerMasterList[row].inputTextKeySet}
I can generate datatable during form initialization.(JSF). Then I want to write javascript for
I want to try out building a simple grid that has a delete column,
As part of a dataTable in a seam JSF page, one column requires the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.