Author: pyaschenko
Date: 2008-03-20 13:26:20 -0400 (Thu, 20 Mar 2008)
New Revision: 7022
Modified:
trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp
trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml
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:
RF-2576
Modified: trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp 2008-03-20 17:06:42
UTC (rev 7021)
+++ trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp 2008-03-20 17:26:20
UTC (rev 7022)
@@ -42,7 +42,7 @@
<h:panelGroup>
<h:inputText value="#{suggestionBox.property}"
id="text"/>
- <rich:suggestionbox id="suggestionBoxId" for="text"
tokens=",["
+ <rich:suggestionbox id="suggestionBoxId" for="text"
rules="#{suggestionBox.rules}"
suggestionAction="#{suggestionBox.autocomplete}"
var="result"
fetchValue="#{result.text}"
@@ -79,7 +79,8 @@
width="#{suggestionBox.width}"
height="#{suggestionBox.height}"
shadowDepth="#{suggestionBox.shadowDepth}"
- cellpadding="#{suggestionBox.cellpadding}">
+ cellpadding="#{suggestionBox.cellpadding}"
+ useSuggestObjects="true">
<a4j:ajaxListener type="org.richfaces.AjaxListener"/>
<h:column>
Modified: trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml
===================================================================
--- trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml 2008-03-20 17:06:42
UTC (rev 7021)
+++ trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml 2008-03-20 17:26:20
UTC (rev 7022)
@@ -87,6 +87,14 @@
</description>
<defaultvalue>true</defaultvalue>
</property>
+ <property>
+ <name>useSuggestObjects</name>
+ <classname>boolean</classname>
+ <description>
+ if true suggested object list will be created and witt be updated every time
when user changes input value
+ </description>
+ <defaultvalue>false</defaultvalue>
+ </property>
<property hidden="true">
<name>submitted</name>
<classname>boolean</classname>
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-20
17:06:42 UTC (rev 7021)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-20
17:26:20 UTC (rev 7022)
@@ -68,7 +68,7 @@
*/
private static final String[] OPTIONS = {"popupClass",
"popupStyle",
"width", "height", "entryClass",
"selectedClass", "param",
- "frequency", "minChars", "tokens",
"rows", "selectValueClass" };
+ "frequency", "minChars", "tokens",
"rows", "selectValueClass", "useSuggestObjects" };
/**
* Shadow depth.
@@ -407,7 +407,6 @@
|| attributes.get("fetchValue") != null) {
options.put("select",
attributes.get("selectValueClass"));
}
-
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-20
17:06:42 UTC (rev 7021)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-20
17:26:20 UTC (rev 7022)
@@ -685,7 +685,7 @@
while (this.startPosition>0 &&
tokens.indexOf(oldValue.charAt(this.startPosition-1))==-1) this.startPosition--;
}
- this.updateItems(oldValue);
+ if (this.options.useSuggestObjects) this.updateItems(oldValue);
}
if (this.getToken().length >= this.options.minChars) {
@@ -787,30 +787,32 @@
whitespace = str.match(/\s+$/);
if (whitespace) endStr = whitespace[0] + endStr;
this.element.value = startStr + value + endStr;
+
+ if (this.options.useSuggestObjects)
+ {
+ var index = 0;
+ if (this.options.tokens.length!=0)
+ {
+ // search index for update item's object
+ var tokens = this.options.tokens.join('');
+ var p = 0;
+ while (p<this.startPosition)
+ {
+ if (tokens.indexOf(this.element.value[p])!=-1) index++;
+ p++;
+ }
+ }
- var index = 0;
- if (this.options.tokens.length!=0)
- {
- // search index for update item's object
- var tokens = this.options.tokens.join('');
- var p = 0;
- while (p<this.startPosition)
+ var itm = {text:value, object:this.fetchValues[this.index]}
+ var flag = (this.selectedItems[index].text != value ||
this.selectedItems[index].object==null ? true : false);
+ this.selectedItemsCache[value] = itm;
+ this.selectedItems[index] = itm;
+ if (flag)
{
- if (tokens.indexOf(this.element.value[p])!=-1) index++;
- p++;
+ //call user listner
+ this.callOnObjectChangeListener(event);
}
- }
-
- // if object null we don't need to request data for it in future
- var itm = {text:value, object:this.fetchValues[this.index]}
- var flag = (this.selectedItems[index].text != value ||
this.selectedItems[index].object==null ? true : false);
- this.selectedItemsCache[value] = itm;
- this.selectedItems[index] = itm;
- if (flag)
- {
- //call user listner
- this.callOnObjectChangeListener(event);
- }
+ }
},
getToken: function() {
@@ -852,7 +854,7 @@
getUpdatedChoices: function(event) {
this.options.parameters[this.options.param] = this.getToken();
- this.options.parameters[this.options.param + "request"] =
this.getItemListForUpdate();
+ if (this.options.useSuggestObjects) this.options.parameters[this.options.param +
"request"] = this.getItemListForUpdate();
if (this.onsubmitFunction && ! this.onsubmitFunction()) {
return;
}
@@ -869,7 +871,7 @@
RichFaces.Position.smartClone(this.element, this.update, this.options);
}
this.updateChoices();
- if (data) {
+ if (this.options.useSuggestObjects && data) {
this.fetchValues = data.suggestionObjects;
this.updateSelectedItems(data.requestedObjects);
if (this.isSelectedItemsUpdated)
Show replies by date