diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2007-11-01 12:18:25 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2007-11-01 12:18:25 +0000 |
commit | 44601df8829b7e1e12c78909fef14264d68fffd8 (patch) | |
tree | 77ade99a5be7cf15808dad9152ec5f48b1aee60d /src/com/itmill/toolkit/ui/Select.java | |
parent | 15f8b8a7e50e01bed9cb83d799d120827a15e940 (diff) | |
download | vaadin-framework-44601df8829b7e1e12c78909fef14264d68fffd8.tar.gz vaadin-framework-44601df8829b7e1e12c78909fef14264d68fffd8.zip |
Select: null selections without nullselectionItemId
svn changeset:2655/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/Select.java')
-rw-r--r-- | src/com/itmill/toolkit/ui/Select.java | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/com/itmill/toolkit/ui/Select.java b/src/com/itmill/toolkit/ui/Select.java index e480e26474..567aa16068 100644 --- a/src/com/itmill/toolkit/ui/Select.java +++ b/src/com/itmill/toolkit/ui/Select.java @@ -65,7 +65,7 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { /** * Holds value of property pageLength. 0 disables paging. */ - protected int pageLength = 15; + protected int pageLength = 10; // current page when the user is 'paging' trough options private int currentPage; @@ -132,8 +132,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { if (isNewItemsAllowed()) { target.addAttribute("allownewitem", true); } + + boolean needNullSelectOption = false; if (isNullSelectionAllowed()) { target.addAttribute("nullselect", true); + needNullSelectOption = getNullSelectionItemId() == null; } // Constructs selected keys array @@ -173,10 +176,29 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { * target.addAttribute("totalMatches", this.optionFilter * .getMatchCount()); } else { i = getItemIds().iterator(); } */ + target.startTag("options"); + + boolean paintNullSelection = needNullSelectOption + && (currentPage == 0 && (filterstring == null + || filterstring.equals("") || filterstring.equals("-"))); + + if (paintNullSelection) { + target.startTag("so"); + target.addAttribute("caption", "-"); + target.addAttribute("key", ""); + target.endTag("so"); + } + List options = getFilteredOptions(); if (options.size() > this.pageLength) { int first = this.currentPage * this.pageLength; int last = first + this.pageLength; + if(needNullSelectOption) { + if(currentPage > 0) { + first--; + } + last--; + } if (options.size() < last) { last = options.size(); } @@ -185,7 +207,6 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { Iterator i = options.iterator(); // Paints the available selection options from data source - target.startTag("options"); while (i.hasNext()) { // Gets the option attribute values @@ -212,9 +233,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { } target.endTag("options"); - target.addAttribute("totalitems", size()); + target.addAttribute("totalitems", size() + + (needNullSelectOption ? 1 : 0)); if (this.filteredOptions != null) { - target.addAttribute("totalMatches", this.filteredOptions.size()); + target.addAttribute("totalMatches", this.filteredOptions.size() + + (needNullSelectOption ? 1 : 0)); } // Paint variables |