Datatable row index problem

Posted on 2009-02-16
Last Modified: 2013-11-24
I have a problem with Sun's JSF datatable component. If two persons are working on the same page containing h:datatable component and one of them make the action, that change contents of the table (for example removes one row), second (without refreshing!) when clicks on the specific row, gets the index of different one!

It hasn't happened when I run my web app on Tomcat 5. Now I use 6 (JBoss Web 2.0.1) and I have the same problem on each page containing datatable...

Obviously myDataTable.getRowIndex() is used in backend to identify row. And it's enumerated from 0, incremented by 1. So if I have table like this:

0 A
1 B
2 C
3 D

I load page in two windows, in one I delete row with index 1 (B). Now in second (not refreshed) I want to delete index 2 (C). As a result, D will be deleted as after first delete it has index 2 now...

I hope I explained good enough. I load the table, meanwhile someone update it, I don't know about it and I delete wrong row because indexation has changed...

<h:dataTable binding="#{page1.myDataTable}"   headerClass="list-header" id="myDataTable" rowClasses="list-row-even,list-row-odd" rows="#{page1.tableRowsNo}"

                                    value="#{page1.myTableValue}" var="currentRow" width="99%">


<a4j:commandButton id="button_first" immediate="true"

                                            onclick="submitActiont('#{page1.myDataTable.rowIndex}'')" style="width: 50px"

                                                styleClass="Btn2" value="Edit"/>


public String editButton_action() {

        Integer requestId = 


// getting this:

// myDataTable.getRowIndex();

// is the problem



Open in new window

Question by:szczecin
    LVL 22

    Expert Comment

    You have binded dataTable to a property (HtmlDataTable type) in the backing bean, so why use row index, when you already have "myId" of currently selected row?

    Integer requestId = ((model.myTableDataModel)myDataTable.getRowData()).getMyId();

    So get the object by yourID, not by table row index.

    Accepted Solution

    the problem is that (I think), .getRowData() uses table row index to identify object's myId.

    anyway, I solved it by changing datatable to Tomahawk's one and adding attribute preserveDataModel="true"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now