topPosition += tb.getOffsetHeight();
setPopupPosition(x, topPosition);
- final int first = currentPage * pageLength
- + (nullSelectionAllowed && currentPage > 0 ? 0 : 1);
- final int last = first + currentSuggestions.size() - 1;
- final int matches = totalSuggestions
- - (nullSelectionAllowed ? 1 : 0);
+ int nullOffset = (nullSelectionAllowed ? 1 : 0);
+ boolean firstPage = (currentPage == 0);
+ final int first = currentPage * pageLength + 1
+ - (firstPage ? 0 : nullOffset);
+ final int last = first + currentSuggestions.size() - 1
+ - (firstPage ? nullOffset : 0);
+ final int matches = totalSuggestions - nullOffset;
if (last > 0) {
// nullsel not counted, as requested by user
DOM.setInnerText(status, (matches == 0 ? 0 : first)
}
// We don't need to show arrows or statusbar if there is only one
// page
- if (matches <= pageLength) {
+ if (totalSuggestions <= pageLength) {
setPagingEnabled(false);
} else {
setPagingEnabled(true);
--- /dev/null
+package com.vaadin.tests.tickets;\r
+\r
+import com.vaadin.Application;\r
+import com.vaadin.ui.ComboBox;\r
+import com.vaadin.ui.Window;\r
+\r
+/**\r
+ * #5053: Last ComboBox item may not be shown if null selection enabled\r
+ */\r
+public class Ticket5053 extends Application {\r
+\r
+ @Override\r
+ public void init() {\r
+ Window main = new Window();\r
+ setMainWindow(main);\r
+\r
+ ComboBox combobox = new ComboBox("My ComboBox");\r
+\r
+ // Enable null selection\r
+ combobox.setNullSelectionAllowed(true);\r
+ // Add the item that marks 'null' value\r
+ String nullitem = "-- none --";\r
+ combobox.addItem(nullitem);\r
+ // Designate it was the 'null' value marker\r
+ combobox.setNullSelectionItemId(nullitem);\r
+\r
+ // Add some other items\r
+ for (int i = 0; i < 10; i++) {\r
+ combobox.addItem("Item " + i);\r
+ }\r
+\r
+ main.addComponent(combobox);\r
+ }\r
+\r
+}\r