Author: pyaschenko
Date: 2011-01-19 09:50:10 -0500 (Wed, 19 Jan 2011)
New Revision: 21083
Modified:
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
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/AutocompleteBase.js
trunk/ui/input/ui/src/main/templates/autocomplete.template.xml
Log:
http://jira.jboss.com/jira/browse/RF-10166
added new functionality for setValue + bugfix
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 2011-01-19
13:50:02 UTC (rev 21082)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2011-01-19
14:50:10 UTC (rev 21083)
@@ -83,7 +83,7 @@
@Attribute
public abstract String getFilterFunction();
- @Attribute
+ @Attribute(defaultValue = "rf-au-itm-sel")
public abstract String getSelectedItemClass();
@Attribute
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 2011-01-19
13:50:02 UTC (rev 21082)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2011-01-19
14:50:10 UTC (rev 21083)
@@ -308,17 +308,6 @@
throw new UnsupportedOperationException();
}
- protected String getSelectedItemClassOrDefault(UIComponent component) {
- String value = "";
- if (component instanceof AbstractAutocomplete) {
- value = ((AbstractAutocomplete) component).getSelectedItemClass();
- if (value == null || value.length() == 0) {
- value = "rf-au-sel";
- }
- }
- return value;
- }
-
protected int getMinCharsOrDefault(UIComponent component) {
int value = 1;
if (component instanceof AbstractAutocomplete) {
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 2011-01-19
13:50:02 UTC (rev 21082)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js 2011-01-19
14:50:10 UTC (rev 21083)
@@ -100,7 +100,7 @@
$super.constructor.call(this, componentId, componentId+ID.SELECT, fieldId, options);
this.attachToDom();
this.options = $.extend(this.options, defaultOptions, options);
- this.value = this.__getSubValue();
+ this.value = "";
this.index = -1;
this.isFirstAjax = true;
updateTokenOptions.call(this);
@@ -205,17 +205,17 @@
if( this.options.autofill && value.toLowerCase().indexOf(inputValue)==0) {
var field = rf.getDomElement(this.fieldId);
var start = rf.Selection.getStart(field);
- this.setInputValue(inputValue + value.substring(inputValue.length));
+ this.__setInputValue(inputValue + value.substring(inputValue.length));
var end = start+value.length - inputValue.length;
rf.Selection.set(field, start, end);
}
};
- var callAjax = function(event, value, callback) {
+ var callAjax = function(event, callback) {
clearItems.call(this);
- rf.getDomElement(this.id+ID.VALUE).value = value;
+ rf.getDomElement(this.id+ID.VALUE).value = this.value;
var _this = this;
var _event = event;
@@ -224,7 +224,7 @@
if (_this.options.lazyClientMode && _this.value.length!=0) {
updateItemsFromCache.call(_this, _this.value);
}
- if (_this.focused && _this.items.length!=0 && callback) {
+ if ((_this.focused || _this.isMouseDown) && _this.items.length!=0 &&
callback) {
callback.call(_this, _event);
}
if (!callback && _this.isVisible && _this.options.selectFirst) {
@@ -317,17 +317,17 @@
callback.call(this, event);
}
if (event.which == rf.KEYS.RETURN || event.type == "click") {
- this.setInputValue(subValue);
+ this.__setInputValue(subValue);
} else if (this.options.selectFirst) {
selectItem.call(this, event, 0);
}
} else {
if (event.which == rf.KEYS.RETURN || event.type == "click") {
- this.setInputValue(subValue);
+ this.__setInputValue(subValue);
}
if (subValue.length>=this.options.minChars) {
if ((this.options.ajaxMode || this.options.lazyClientMode) &&
oldValue!=subValue) {
- callAjax.call(this, event, subValue, callback);
+ callAjax.call(this, event, callback);
}
} else {
if (this.options.ajaxMode) {
@@ -365,7 +365,7 @@
return result;
} else {
- return this.getInputValue();
+ return this.getValue();
}
};
@@ -407,7 +407,9 @@
// called from AutocompleteBase when not actually value changed
if (this.items.length==0 && this.isFirstAjax) {
if ((this.options.ajaxMode && subValue.length>=this.options.minChars) ||
this.options.lazyClientMode) {
- callAjax.call(this, event, subValue);
+ this.value = subValue;
+ callAjax.call(this, event, this.show);
+ return true;
}
}
return;
@@ -420,6 +422,9 @@
return $super.__updateInputValue.call(this, value);
}
},
+ __setInputValue: function (value) {
+ this.currentValue = this.__updateInputValue(value);
+ },
__onChangeValue: onChangeValue,
/*
* Override abstract protected methods
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/AutocompleteBase.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/AutocompleteBase.js 2011-01-19
13:50:02 UTC (rev 21082)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/AutocompleteBase.js 2011-01-19
14:50:10 UTC (rev 21083)
@@ -26,7 +26,8 @@
this.fieldId = fieldId;
this.options = $.extend({}, defaultOptions, options);
this.namespace = this.namespace || "."+rf.Event.createNamespace(this.name,
this.selectId);
- this.currentValue = this.getInputValue();
+ this.currentValue = "";
+ this.isChanged = this.getValue().length!=0;
bindEventHandlers.call(this);
};
@@ -88,7 +89,7 @@
var onFocus = function (event) {
if (!this.focused) {
- this.__focusValue = this.getInputValue();
+ this.__focusValue = this.getValue();
this.focused = true;
this.invokeEvent("focus", rf.getDomElement(this.fieldId), event);
}
@@ -106,7 +107,7 @@
if (this.focused) {
this.focused=false;
this.invokeEvent("blur", rf.getDomElement(this.fieldId), event);
- if (this.__focusValue != this.getInputValue()) {
+ if (this.__focusValue != this.getValue()) {
this.invokeEvent("change", rf.getDomElement(this.fieldId), event);
}
}
@@ -117,14 +118,14 @@
};
var onChange = function (event) {
- var value = this.getInputValue();
+ var value = this.getValue();
var flag = value != this.currentValue;
//TODO: is it needed to chesk keys?
//TODO: we need to set value when autoFill used when LEFT or RIGHT was pressed
if (event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT || flag) {
if (flag) {
+ this.currentValue = this.getValue();
this.__onChangeValue(event, undefined, (!this.isVisible ? this.show : undefined));
- this.currentValue = this.getInputValue();
} else if (this.isVisible) {
this.__onChangeValue(event);
}
@@ -132,8 +133,12 @@
};
var onShow = function (event) {
- this.__updateState(event);
- this.show(event);
+ if (this.isChanged) {
+ this.isChanged = false;
+ onChange.call(this,{});
+ } else {
+ !this.__updateState(event) && this.show(event);
+ }
};
var onKeyDown = function (event) {
@@ -218,6 +223,15 @@
}
};
+ var updateInputValue = function (value) {
+ if (this.fieldId) {
+ rf.getDomElement(this.fieldId).value = value;
+ return value;
+ } else {
+ return "";
+ }
+ }
+
/*
* Prototype definition
*/
@@ -232,23 +246,18 @@
getNamespace: function () {
return this.namespace;
},
- getInputValue: function () {
+ getValue: function () {
return this.fieldId ? rf.getDomElement(this.fieldId).value : "";
},
- setInputValue: function (value) {
- this.currentValue = this.__updateInputValue(value);
+ setValue: function (value) {
+ if (value==this.currentValue) return;
+ updateInputValue.call(this, value);
+ this.isChanged = true;
},
/*
* Protected methods
*/
- __updateInputValue: function (value) {
- if (this.fieldId) {
- rf.getDomElement(this.fieldId).value = value;
- return value;
- } else {
- return "";
- }
- },
+ __updateInputValue: updateInputValue,
/*
* abstract protected methods
*/
Modified: trunk/ui/input/ui/src/main/templates/autocomplete.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/autocomplete.template.xml 2011-01-19 13:50:02 UTC
(rev 21082)
+++ trunk/ui/input/ui/src/main/templates/autocomplete.template.xml 2011-01-19 14:50:10 UTC
(rev 21083)
@@ -74,10 +74,9 @@
<cdk:object name="mode" type="Object"
value="#{component.attributes['mode']}" />
<cdk:scriptObject name="options">
<cdk:scriptOption name="buttonId"
value="#{clientId}Button" />
- <cdk:scriptOption attributes="filterFunction autofill
disabled selectFirst tokens" />
+ <cdk:scriptOption attributes="selectedItemClass
filterFunction autofill disabled selectFirst tokens" />
<cdk:scriptOption attributes="onbegin oncomplete onerror
onbeforedomupdate onchange onselectitem onfocus onblur"
wrapper="eventHandler"/>
<cdk:scriptOption name="minChars"
value="#{getMinCharsOrDefault(component)}" />
- <cdk:scriptOption name="selectedItemClass"
value="#{getSelectedItemClassOrDefault(component)}" />
<cdk:scriptOption name="filterFunction"
value="#{getClientFilterFunction(component)}" />
<cdk:scriptOption name="isCachedAjax"
value="#{'ajax'==mode ? false : true}" defaultValue="true"
/>
<cdk:scriptOption name="ajaxMode"
value="#{'client'==mode||'lazyClient'==mode ? false : true}"
defaultValue="true" />