[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Datatable row index problem

Posted on 2009-02-16
2
Medium Priority
?
4,174 Views
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"/>
</h:datatable>
 
public String editButton_action() {
        Integer requestId = 
                ((model.myTableDataModel)myDataTable.getRowData()).getMyId();
// getting this:
// myDataTable.getRowIndex();
// is the problem
[...]
}

Open in new window

0
Comment
Question by:szczecin
2 Comments
 
LVL 22

Expert Comment

by:mbonaci
ID: 23651025
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.
0
 

Accepted Solution

by:
szczecin earned 0 total points
ID: 23654398
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"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
A solution for Fortify Path Manipulation.
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.
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

873 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