Author: nbelaevski
Date: 2008-03-14 10:33:04 -0400 (Fri, 14 Mar 2008)
New Revision: 6820
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
http://jira.jboss.com/jira/browse/RF-1774
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java
===================================================================
---
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java 2008-03-14
14:31:43 UTC (rev 6819)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java 2008-03-14
14:33:04 UTC (rev 6820)
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -318,6 +319,35 @@
private int rowNumber = -1;
+ private Object getModelValuesData() {
+ int first = getFirst();
+ int rows = getRows();
+ int rowIndex = getRowIndex();
+
+ setFirst(0);
+ setRows(0);
+ setRowIndex(-1);
+
+ List<Object> results = new ArrayList<Object>();
+ int j = 0;
+ boolean stop = false;
+
+ while (!stop) {
+ setRowIndex(j++);
+ if (isRowAvailable()) {
+ results.add(getRowData());
+ } else {
+ stop = true;
+ }
+ }
+
+ setFirst(first);
+ setRows(rows);
+ setRowIndex(rowIndex);
+
+ return results;
+ }
+
private Object getRequestedValuesData() {
MethodExpression suggestingAction = getSuggestionAction();
SubmittedValue valueHolder = (SubmittedValue) getSubmitedValue();
@@ -329,10 +359,12 @@
int first = getFirst();
int rows = getRows();
int rowIndex = getRowIndex();
+ Object value = getValue();
+
setFirst(0);
setRows(0);
- List results = new ArrayList();
+ Map<String, Object> results = new HashMap<String, Object>();
for (int i = 0; i < requestedValues.length; i++) {
String requestedValue = requestedValues[i];
if (requestedValue != null) {
@@ -350,27 +382,23 @@
Object fetchValue = getFetchValue();
if (fetchValue != null) {
if (requestedValue.equalsIgnoreCase(fetchValue.toString())) {
- results.add(getRowData());
+ results.put(requestedValue, getRowData());
stop = true;
}
}
} else {
- results.add(null);
stop = true;
}
}
- } else {
- results.add(null);
}
}
- setData(results);
-
setFirst(first);
setRows(rows);
setRowIndex(rowIndex);
-
- return results;
+ setValue(value);
+
+ return results;
}
}
@@ -390,10 +418,16 @@
super.broadcast(event);
if (event instanceof AjaxEvent) {
FacesContext context = getFacesContext();
- Object data = getRequestedValuesData();
+ setupValue(context);
+
+ Object modelValues = getModelValuesData();
+ Object requestedData = getRequestedValuesData();
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- if (null != data) {
- ajaxContext.setResponseData(data);
+ if (null != modelValues || null != requestedData) {
+ Map<String,Object> map = new HashMap<String, Object>();
+ map.put("suggestionObjects", modelValues);
+ map.put("requestedObjects", requestedData);
+ ajaxContext.setResponseData(map);
}
AjaxRendererUtils.addRegionsFromComponent(this, context);
AjaxRendererUtils.addRegionByName(context, this, this.getId());
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
===================================================================
---
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-14
14:31:43 UTC (rev 6819)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-14
14:33:04 UTC (rev 6820)
@@ -292,7 +292,6 @@
throws IOException {
UISuggestionBox suggestionBox = (UISuggestionBox) component;
if (suggestionBox.isSubmitted()) {
- suggestionBox.setupValue(context);
body.encode(getTemplateContext(context, suggestionBox));
// Replace rendered area ID from component to suggestion table
suggestionBox.setRowIndex(-1);
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
---
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-14
14:31:43 UTC (rev 6819)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-14
14:33:04 UTC (rev 6820)
@@ -686,9 +686,9 @@
var tokens = this.options.tokens.join('');
this.startPosition = this.endPosition =
Richfaces.Selection.getStart(this.element);
- while (this.endPosition<oldValue.length &&
tokens.indexOf(oldValue[this.endPosition])==-1) this.endPosition++;
+ while (this.endPosition<oldValue.length &&
tokens.indexOf(oldValue.charAt(this.endPosition))==-1) this.endPosition++;
- while (this.startPosition>0 &&
tokens.indexOf(oldValue[this.startPosition-1])==-1) this.startPosition--;
+ while (this.startPosition>0 &&
tokens.indexOf(oldValue.charAt(this.startPosition-1))==-1) this.startPosition--;
}
this.updateItems(oldValue);
@@ -823,7 +823,7 @@
getUpdatedChoices: function(event) {
this.options.parameters[this.options.param] = this.getToken();
// TODO-done: add string list parameter for the values that need object from server
- this.options.parameters["inputvaluerequest"] =
this.getItemListForUpdate();
+ this.options.parameters[this.options.param + "request"] =
this.getItemListForUpdate();
if (this.onsubmitFunction && ! this.onsubmitFunction()) {
return;
}
@@ -840,10 +840,13 @@
RichFaces.Position.smartClone(this.element, this.update, this.options);
}
this.updateChoices();
- this.fetchValues = data; // use data.suggestionObjects
- // TODO-done: add update item objects from data
- this.updateSelectedItems(data); // use data.requestedObjects
- LOG.debug("Choices updated");
+ if (data) {
+ this.fetchValues = data.suggestionObjects; // use data.suggestionObjects
+ // TODO-done: add update item objects from data
+ this.updateSelectedItems(data.requestedObjects); // use data.requestedObjects
+
+ LOG.debug("Choices updated");
+ }
if (this.options.onajaxcomplete) {
this.options.onajaxcomplete(request, event);
}