private String prevfilterstring;
private List filteredOptions;
+ /**
+ * Flag to indicate that request repaint is called by filter request only
+ */
+ private boolean optionRequest;
+
/* Constructors ********************************************************* */
/* Component methods **************************************************** */
}
List options = getFilteredOptions();
- if (options.size() > pageLength) {
- int first = currentPage * pageLength;
- int last = first + pageLength;
- if (needNullSelectOption) {
- if (currentPage > 0) {
- first--;
- }
- last--;
- }
- if (options.size() < last) {
- last = options.size();
- }
- options = options.subList(first, last);
- }
+ options = sanitetizeList(options, needNullSelectOption);
final Iterator i = options.iterator();
// Paints the available selection options from data source
target.addVariable(this, "filter", filterstring);
target.addVariable(this, "page", currentPage);
+ optionRequest = true;
+ }
+
+ /**
+ * Makes correct sublist of given list of options.
+ *
+ * If paint is not an option request (affected by page or filter change),
+ * page will be the one where possible selection exists.
+ *
+ * Detects proper first and last item in list to return right page of
+ * options.
+ *
+ * @param options
+ * @param needNullSelectOption
+ * flag to indicate if nullselect option needs to be taken
+ * into consideration
+ */
+ private List sanitetizeList(List options, boolean needNullSelectOption) {
+
+ if (options.size() > pageLength) {
+ int first = currentPage * pageLength;
+ int last = first + pageLength;
+ if (needNullSelectOption) {
+ if (currentPage > 0) {
+ first--;
+ }
+ last--;
+ }
+ if (options.size() < last) {
+ last = options.size();
+ }
+ if (!optionRequest) {
+ // TODO ensure proper page
+ if (!isMultiSelect()) {
+ Object selection = getValue();
+ if (selection != null) {
+ int index = options.indexOf(selection);
+ if (index != -1 && (index < first || index >= last)) {
+ int newPage = (index + (needNullSelectOption ? 1
+ : 0))
+ / pageLength;
+ currentPage = newPage;
+ return sanitetizeList(options, needNullSelectOption);
+ }
+ }
+ }
+ }
+
+ return options.subList(first, last);
+ } else {
+ return options;
+ }
}
protected List getFilteredOptions() {
if (filterstring != null) {
filterstring = filterstring.toLowerCase();
}
- requestRepaint();
+ optionRepaint();
return;
}
}
}
+ public void requestRepaint() {
+ super.requestRepaint();
+ optionRequest = false;
+ prevfilterstring = filterstring;
+ filterstring = null;
+ }
+
+ private void optionRepaint() {
+ super.requestRepaint();
+ }
+
/**
* Gets the component UIDL tag.
*