Author: pyaschenko
Date: 2010-09-02 12:57:55 -0400 (Thu, 02 Sep 2010)
New Revision: 19100
Modified:
trunk/examples/input-demo/src/main/webapp/autocomplete.xhtml
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js
Log:
https://jira.jboss.org/browse/RF-9106
Modified: trunk/examples/input-demo/src/main/webapp/autocomplete.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/autocomplete.xhtml 2010-09-02 15:13:52 UTC
(rev 19099)
+++ trunk/examples/input-demo/src/main/webapp/autocomplete.xhtml 2010-09-02 16:57:55 UTC
(rev 19100)
@@ -23,7 +23,7 @@
block text block text block text block text block text block text
block text block
- <input:autocomplete mode="#{autoCompleteBean.mode}" minChars="2"
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
fetchValue="#{country.name}" showButton="true">
+ <input:autocomplete clientFilter="if(subString.length>1)
if(value.indexOf(subString)!=-1) return true;"
mode="#{autoCompleteBean.mode}" minChars="2"
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
fetchValue="#{country.name}" showButton="true">
#{country.name} #{country.iso} #{country.domain}
</input:autocomplete>
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2010-09-02
15:13:52 UTC (rev 19099)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2010-09-02
16:57:55 UTC (rev 19100)
@@ -195,6 +195,9 @@
@Attribute(events = @EventName("beforedomupdate"))
public abstract String getOnbeforedomupdate();
+
+ @Attribute
+ public abstract String getClientFilter();
@Override
public Converter getConverter() {
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-09-02
15:13:52 UTC (rev 19099)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-09-02
16:57:55 UTC (rev 19100)
@@ -46,6 +46,7 @@
import javax.servlet.jsp.jstl.sql.Result;
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
@@ -72,6 +73,19 @@
})
public abstract class AutocompleteRendererBase extends InputRendererBase implements
MetaComponentRenderer {
+ public JSFunctionDefinition getClientFilterFunction(UIComponent component) {
+ AbstractAutocomplete autocomplete = (AbstractAutocomplete) component;
+ String clientFilter =
(String)autocomplete.getAttributes().get("clientFilter");
+ if (clientFilter != null && clientFilter.length() != 0) {
+ JSFunctionDefinition clientFilterFunction = new
JSFunctionDefinition("subString");
+ clientFilterFunction.addParameter("value");
+ clientFilterFunction.addToBody(clientFilter);
+ return clientFilterFunction;
+ }
+
+ return null;
+ }
+
public String getScriptOptions(UIComponent component) {
Map<String, Object> attributes = component.getAttributes();
Map<String, Object> options = new HashMap<String, Object>();
@@ -89,6 +103,7 @@
utils.addToScriptHash(options, "onerror",
attributes.get("onerror"));
utils.addToScriptHash(options, "onbeforedomupdate",
attributes.get("onbeforedomupdate"));
utils.addToScriptHash(options, "onchange",
attributes.get("onchange"));
+ utils.addToScriptHash(options, "filterFunction",
getClientFilterFunction(component));
String mode = (String)attributes.get("mode");
if (mode != null) {
if (mode.equals("ajax")){
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js 2010-09-02
15:13:52 UTC (rev 19099)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js 2010-09-02
16:57:55 UTC (rev 19100)
@@ -29,7 +29,7 @@
return result;
}
- var getItems = function (key) {
+ var getItems = function (key, filterFunction) {
key = key.toLowerCase();
var newCache = [];
@@ -40,12 +40,17 @@
if (this.cache[key]) {
newCache = this.cache[key];
} else {
+ var useCustomFilterFunction = typeof filterFunction == "function";
var itemsCache = this.cache[this.key];
for (var i = 0; i<this.values.length; i++) {
var value = this.values[i];
- var p = value.indexOf(key);
- if (p == 0) {
+ if (useCustomFilterFunction && filterFunction(key, value)) {
newCache.push(itemsCache[i]);
+ } else {
+ var p = value.indexOf(key);
+ if (p == 0) {
+ newCache.push(itemsCache[i]);
+ }
}
}
@@ -119,7 +124,8 @@
lazyClientMode:false,
isCachedAjax:true,
tokens: "",
- attachToBody:true
+ attachToBody:true,
+ filterFunction: undefined
};
var ID = {
@@ -274,7 +280,7 @@
};
var updateItemsFromCache = function (value) {
- var newItems = this.cache.getItems(value);
+ var newItems = this.cache.getItems(value, this.options.filterFunction);
this.items = $(newItems);
//TODO: works only with simple markup, not with <tr>
$(rf.getDomElement(this.id+ID.ITEMS)).empty().append(this.items);