aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/ui/Table.java
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2008-08-15 08:20:23 +0000
committerMarc Englund <marc.englund@itmill.com>2008-08-15 08:20:23 +0000
commitcee7be72cebe5eba758ce9da646ee327329d3049 (patch)
treed92a7c2aeaa4acc738acb5a4bf0e5b4be4450444 /src/com/itmill/toolkit/ui/Table.java
parent7728276d115fa8a175e506403b946734f74c5adb (diff)
downloadvaadin-framework-cee7be72cebe5eba758ce9da646ee327329d3049.tar.gz
vaadin-framework-cee7be72cebe5eba758ce9da646ee327329d3049.zip
Fixes #1981 (some selections lost when scrolling)
svn changeset:5187/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/Table.java')
-rw-r--r--src/com/itmill/toolkit/ui/Table.java30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/com/itmill/toolkit/ui/Table.java b/src/com/itmill/toolkit/ui/Table.java
index bdcca0f5d5..02d07de22c 100644
--- a/src/com/itmill/toolkit/ui/Table.java
+++ b/src/com/itmill/toolkit/ui/Table.java
@@ -1751,14 +1751,26 @@ public class Table extends AbstractSelect implements Action.Container,
}
// selection support
- String[] selectedKeys;
+ LinkedList selectedKeys = new LinkedList();
if (isMultiSelect()) {
- selectedKeys = new String[((Set) getValue()).size()];
+ // only paint selections that are currently visible in the client
+ HashSet sel = new HashSet((Set) getValue());
+ Collection vids = getVisibleItemIds();
+ for (Iterator it = vids.iterator(); it.hasNext();) {
+ Object id = it.next();
+ if (sel.contains(id)) {
+ selectedKeys.add(itemIdMapper.key(id));
+ }
+ }
} else {
- selectedKeys = new String[(getValue() == null
- && getNullSelectionItemId() == null ? 0 : 1)];
+ Object value = getValue();
+ if (value == null) {
+ value = getNullSelectionItemId();
+ }
+ if (value != null) {
+ selectedKeys.add(itemIdMapper.key(value));
+ }
}
- int keyIndex = 0;
// Table attributes
if (isSelectable()) {
@@ -1854,9 +1866,8 @@ public class Table extends AbstractSelect implements Action.Container,
target.addAttribute("key", Integer.parseInt(cells[CELL_KEY][i]
.toString()));
if (actionHandlers != null || isSelectable()) {
- if (isSelected(itemId) && keyIndex < selectedKeys.length) {
+ if (isSelected(itemId)) {
target.addAttribute("selected", true);
- selectedKeys[keyIndex++] = (String) cells[CELL_KEY][i];
}
}
@@ -1927,8 +1938,9 @@ public class Table extends AbstractSelect implements Action.Container,
target.endTag("rows");
// The select variable is only enabled if selectable
- if (selectable) {
- target.addVariable(this, "selected", selectedKeys);
+ if (selectable && selectedKeys.size() > 0) {
+ target.addVariable(this, "selected", (String[]) selectedKeys
+ .toArray(new String[selectedKeys.size()]));
}
// The cursors are only shown on pageable table