Author: nbelaevski
Date: 2008-03-23 15:42:52 -0400 (Sun, 23 Mar 2008)
New Revision: 7094
Modified:
trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml
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-2576
Modified: trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml
===================================================================
--- trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml 2008-03-23 19:42:44
UTC (rev 7093)
+++ trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml 2008-03-23 19:42:52
UTC (rev 7094)
@@ -88,7 +88,7 @@
<defaultvalue>true</defaultvalue>
</property>
<property>
- <name>useSuggestObjects</name>
+ <name>usingSuggestObjects</name>
<classname>boolean</classname>
<description>
if true suggested object list will be created and witt be updated every time
when user changes input value
@@ -373,6 +373,5 @@
<name>rowNumber</name>
<classname>java.lang.Object</classname>
</property>
-
</component>
</components>
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-23
19:42:44 UTC (rev 7093)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java 2008-03-23
19:42:52 UTC (rev 7094)
@@ -349,56 +349,58 @@
}
private Object getRequestedValuesData() {
- MethodExpression suggestingAction = getSuggestionAction();
SubmittedValue valueHolder = (SubmittedValue) getSubmitedValue();
FacesContext context = getFacesContext();
- if (null != suggestingAction && valueHolder != null) {
+ if (valueHolder != null) {
String[] requestedValues = valueHolder.getRequestedValues();
if (requestedValues != null) {
- int first = getFirst();
- int rows = getRows();
- int rowIndex = getRowIndex();
- Object value = getValue();
-
- setFirst(0);
- setRows(0);
+ MethodExpression suggestingAction = getSuggestionAction();
+ if (suggestingAction != null) {
+ int first = getFirst();
+ int rows = getRows();
+ int rowIndex = getRowIndex();
+ Object value = getValue();
- Map<String, Object> results = new HashMap<String, Object>();
- for (int i = 0; i < requestedValues.length; i++) {
- String requestedValue = requestedValues[i];
- if (requestedValue != null) {
- setValue(suggestingAction.invoke(
- context.getELContext(), new Object[]{requestedValue}));
+ setFirst(0);
+ setRows(0);
- setRowIndex(-1);
+ Map<String, Object> results = new HashMap<String, Object>();
+ for (int i = 0; i < requestedValues.length; i++) {
+ String requestedValue = requestedValues[i];
+ if (requestedValue != null) {
+ setValue(suggestingAction.invoke(
+ context.getELContext(), new Object[]{requestedValue}));
- int j = 0;
- boolean stop = false;
+ setRowIndex(-1);
- while (!stop) {
- setRowIndex(j++);
- if (isRowAvailable()) {
- Object fetchValue = getFetchValue();
- if (fetchValue != null) {
- if (requestedValue.equalsIgnoreCase(fetchValue.toString())) {
- results.put(requestedValue, getRowData());
- stop = true;
+ int j = 0;
+ boolean stop = false;
+
+ while (!stop) {
+ setRowIndex(j++);
+ if (isRowAvailable()) {
+ Object fetchValue = getFetchValue();
+ if (fetchValue != null) {
+ if (requestedValue.equalsIgnoreCase(fetchValue.toString())) {
+ results.put(requestedValue, getRowData());
+ stop = true;
+ }
}
+ } else {
+ stop = true;
}
- } else {
- stop = true;
}
}
}
+
+ setFirst(first);
+ setRows(rows);
+ setRowIndex(rowIndex);
+ setValue(value);
+
+ return results;
}
-
- setFirst(first);
- setRows(rows);
- setRowIndex(rowIndex);
- setValue(value);
-
- return results;
}
}
@@ -426,7 +428,11 @@
if (null != modelValues || null != requestedData) {
Map<String,Object> map = new HashMap<String, Object>();
map.put("suggestionObjects", modelValues);
- map.put("requestedObjects", requestedData);
+
+ if (requestedData != null) {
+ map.put("requestedObjects", requestedData);
+ }
+
ajaxContext.setResponseData(map);
}
AjaxRendererUtils.addRegionsFromComponent(this, context);
@@ -558,4 +564,7 @@
*/
public abstract void setPopupStyle(String value);
+ public abstract boolean isUsingSuggestObjects();
+
+ public abstract void setUsingSuggestObjects(boolean usingSuggestObjects);
}
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-23
19:42:44 UTC (rev 7093)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-23
19:42:52 UTC (rev 7094)
@@ -177,25 +177,29 @@
suggestionBox.setSubmitted(true);
component.queueEvent(
new AjaxSuggestionEvent(component, elementValue));
- String requestedParamName = paramName + "request";
+
String[] requestedValues = null;
- String requestedValuesParam = requestParameterMap.get(requestedParamName);
-
- if (requestedValuesParam != null) {
- String requestedString = requestedValuesParam.toString();
- Pattern pattern = getTokensPattern(component);
-
- if (pattern != null) {
- requestedValues = pattern.split(requestedString);
+
+ if (suggestionBox.isUsingSuggestObjects()) {
+ String requestedParamName = paramName + "request";
+ String requestedValuesParam =
requestParameterMap.get(requestedParamName);
+
+ if (requestedValuesParam != null) {
+ String requestedString = requestedValuesParam.toString();
+ Pattern pattern = getTokensPattern(component);
+
+ if (pattern != null) {
+ requestedValues = pattern.split(requestedString);
+ } else {
+ requestedValues = new String[] {requestedString};
+ }
} else {
- requestedValues = new String[] {requestedString};
+ //TODO nick - review together with pasha
}
- } else {
- //TODO nick - review together with pasha
}
- suggestionBox.setSubmitedValue(elementValue,
+
+ suggestionBox.setSubmitedValue(elementValue,
requestedValues);
-
}
}
@@ -407,6 +411,10 @@
|| attributes.get("fetchValue") != null) {
options.put("select",
attributes.get("selectValueClass"));
}
+
+ UISuggestionBox suggestionBox = (UISuggestionBox) component;
+ options.put("usingSuggestObjects",
suggestionBox.isUsingSuggestObjects());
+
submitSuggest.addParameter(options);
script.append(submitSuggest.toScript()).append(";\n");
return "Richfaces.onAvailable('" + targetId + "',
function() {" + script.toString() + "});";
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-23
19:42:44 UTC (rev 7093)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-23
19:42:52 UTC (rev 7094)
@@ -685,7 +685,7 @@
while (this.startPosition>0 &&
tokens.indexOf(oldValue.charAt(this.startPosition-1))==-1) this.startPosition--;
}
- if (this.options.useSuggestObjects) this.updateItems(oldValue);
+ if (this.options.usingSuggestObjects) this.updateItems(oldValue);
}
if (this.getToken().length >= this.options.minChars) {
@@ -788,7 +788,7 @@
if (whitespace) endStr = whitespace[0] + endStr;
this.element.value = startStr + value + endStr;
- if (this.options.useSuggestObjects)
+ if (this.options.usingSuggestObjects)
{
var index = 0;
if (this.options.tokens.length!=0)
@@ -854,7 +854,7 @@
getUpdatedChoices: function(event) {
this.options.parameters[this.options.param] = this.getToken();
- if (this.options.useSuggestObjects) this.options.parameters[this.options.param +
"request"] = this.getItemListForUpdate();
+ if (this.options.usingSuggestObjects) this.options.parameters[this.options.param
+ "request"] = this.getItemListForUpdate();
if (this.onsubmitFunction && ! this.onsubmitFunction()) {
return;
}
@@ -871,7 +871,7 @@
RichFaces.Position.smartClone(this.element, this.update, this.options);
}
this.updateChoices();
- if (this.options.useSuggestObjects && data) {
+ if (this.options.usingSuggestObjects && data) {
this.fetchValues = data.suggestionObjects;
this.updateSelectedItems(data.requestedObjects);
if (this.isSelectedItemsUpdated)