-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I have a routine where you click on a Toolbarbutton in a grid, the index of the row the tbb is in is found, then the corresponding element is returned from the backing list model. I works all over the place except for one rare, non-reproducible case with the same 2 or 3 users, not everyone else. I put in some debugging code. This method gets called after the normal routine fails:
StringBuilder debug = new StringBuilder("Trying to find user for room control: " + tbbAddToRoom + "\n"); // try again to find user based on component, we're trying to get information to help troubleshoot ticket #243 ListModel listModel = ... Grid grid = ... Object data = null; Component rowComponent = null; Component parent = tbbAddToRoom.getParent(); while ((rowComponent == null) && (parent != null)) { if (parent instanceof Row) { debug.append("Found Row: " + parent + "\n"); rowComponent = parent; // to ensure it's loaded grid.renderRow((Row) rowComponent); int index = grid.getRows().getChildren().indexOf(rowComponent); debug.append("Index of row in rows: " + index + "\n"); if (index == -1) { debug.append("Trying to find by row parent\n"); Component rows = rowComponent.getParent(); if (rows != null) { index = rows.getChildren().indexOf(rowComponent); debug.append("Index of row in row parent: " + index + "\n"); } else { debug.append("Row has no Rows parent\n"); } } if (index != -1) data = listModel.getElementAt(index); } parent = parent.getParent(); } if (data == null) throw new IllegalStateException("Could not find user by room control:\n" + debug);
And here is the debug output:
java.lang.IllegalStateException: Could not find user by room control:
Trying to find user for room control: <Toolbarbutton z_gu_hfo2>
Found Row: <Row z_gu_gtn2>
Index of row in rows: -1
Trying to find by row parent
Row has no Rows parent
So it appears the tbb is in a Row, but the Row is not in a Rows. How can it be that a tbb is clicked and the row is not attached to a Rows parent? Is it possible grid.renderRow((Row) rowComponent) could mess up the hierarchy?
Thanks.
/Daryl
Interestingly, it sort of semi-failed this time:
Found user by alternate means:
Trying to find user for room control: <Toolbarbutton z_cq_7aq1>
Found Row: <Row z_cq_t6q1>
Index of row in rows: -1
Trying to find by row parent
Index of row in row parent: 2
So now the tbb is not a member of the rows of the grid I've got a final reference to, but it still seems to have a Rows as a parent.
/Daryl
Hi dastultz,
From your description it's hard to draw a conclusion at the first glance. One of my guess is that there is a timing where the Row is somehow detached from the Rows, but I could be wrong.
To work around, maybe you can try to use Row#setValue() or component attribute to keep the index information on the Row, so you don't need to count for the index from Rows?
Regards,
Simon
Asked: 2010-11-12 11:20:04 +0800
Seen: 307 times
Last updated: Nov 29 '10