We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Datatable row index problem

szczecin
szczecin asked
on
Medium Priority
4,195 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

Comment
Watch Question

Commented:
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.
Commented:
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"

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.