Author: pyaschenko
Date: 2010-09-17 04:01:17 -0400 (Fri, 17 Sep 2010)
New Revision: 19231
Modified:
trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
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
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:
https://jira.jboss.org/browse/RF-9105
onblur, onfocus, onchange, onselectitem user event handlers support was added
handlers script output was fixed
Modified:
trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
===================================================================
---
trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-09-17
07:57:19 UTC (rev 19230)
+++
trunk/core/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-09-17
08:01:17 UTC (rev 19231)
@@ -4,6 +4,8 @@
(function ($, richfaces, params) {
+
+ var RICH_CONTAINER = "richfaces";
richfaces.blankFunction = function (){}; //TODO: add it to global library
@@ -50,6 +52,7 @@
* */
richfaces.BaseComponent = function(componentId) {
this.id = componentId;
+ this.options = {};
};
var $p = {};
@@ -149,7 +152,7 @@
$.extend(DerivedClass.prototype, methods);
return DerivedClass;
- },
+ };
$.extend(richfaces.BaseComponent.prototype, (function (params) {
return {
@@ -177,6 +180,11 @@
result[result.length] = this.name;
return result.join(', ');
},
+
+ // TODO: add jsdocs and qunit tests
+ getValue: function() {
+ return;
+ },
/**
* Method returns element's id for event handlers binding.
@@ -204,7 +212,7 @@
source = source || this.id;
var element = richfaces.getDomElement(source);
if (element) {
- element["richfaces"] = element["richfaces"] || {};
+ element[RICH_CONTAINER] = element[RICH_CONTAINER] || {};
element.richfaces.component = this;
}
return element;
@@ -223,7 +231,45 @@
var element = richfaces.getDomElement(source);
element && element.richfaces && (element.richfaces.component=null);
},
+
+ /** TODO: add jsdocs and qunit tests
+ *
+ */
+ invokeEvent: function(eventType, element, event, data) {
+ var handlerResult, result;
+ var eventObj = $.extend({}, event, {type: eventType});
+ if (!eventObj)
+ {
+ if( document.createEventObject )
+ {
+ eventObj = document.createEventObject();
+ eventObj.type = eventType;
+ }
+ else if( document.createEvent )
+ {
+ eventObj = document.createEvent('Events');
+ eventObj.initEvent( eventType, true, false );
+ }
+ }
+ eventObj[RICH_CONTAINER] = {component:this, data: data};
+
+ var eventHandler = this.options['on'+eventType];
+
+ if (typeof eventHandler == "function")
+ {
+ handlerResult = eventHandler.call(element, eventObj);
+ }
+
+ if (richfaces.Event) {
+ result = richfaces.Event.callHandler(this, eventType, data);
+ }
+
+ if (result!=false && handlerResult!=false) result=true;
+
+ return result;
+ },
+
/**
* Destroy method. Will be called before remove component from the page
*
Modified: trunk/examples/input-demo/src/main/webapp/autocomplete.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/autocomplete.xhtml 2010-09-17 07:57:19 UTC
(rev 19230)
+++ trunk/examples/input-demo/src/main/webapp/autocomplete.xhtml 2010-09-17 08:01:17 UTC
(rev 19231)
@@ -3,7 +3,8 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
-
xmlns:input="http://richfaces.org/input">
+
xmlns:input="http://richfaces.org/input"
+
xmlns:a4j="http://richfaces.org/a4j">
<f:view contentType="text/html" />
<h:head>
@@ -18,15 +19,21 @@
<f:selectItem itemValue="client"/>
<f:selectItem itemValue="cachedAjax"/>
<f:selectItem itemValue="ajax"/>
- </h:selectOneMenu>
- <div style="height: 300px; width: 300px; overflow: auto;">Text
+ </h:selectOneMenu><br/>
+ <div style="height: 300px; width: 300px; overflow: auto;
float:left;">Text
block text block text block text block text block text block text
block text block
- <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">
+ <input:autocomplete id="myAutocomplete"
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"
+ onchange="return onEvent.call(this, event);" onselectitem="return
onEvent.call(this, event);" onblur="return onEvent.call(this, event);"
onfocus="return onEvent.call(this, event);">
#{country.name} #{country.iso} #{country.domain}
</input:autocomplete>
-
+ <script type="text/javascript">
+ onEvent = function(event, element, data){
+ RichFaces.log.info("jQuery Event: "+(event instanceof jQuery.Event)+";
event: "+event.type+"; data:"+(data ||
(event['rich']||{})['data'])+"; this.id:"+this.id+";
component:"+
(event['rich']||{})['component']||RichFaces.$(this.id));
+ };
+ RichFaces.Event.bindById("form:myAutocomplete", "selectitem change blur
focus", onEvent);
+ </script>
<br />
<select style="width: 200px" name="select">
<option>ccccc</option>
@@ -60,6 +67,9 @@
block text block text block text block text block text block text
block text block text block
</div>
+ <div>
+ <a4j:log mode="inline"></a4j:log>
+ </div>
</h:form>
</h:body>
</html>
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-17
07:57:19 UTC (rev 19230)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2010-09-17
08:01:17 UTC (rev 19231)
@@ -177,13 +177,10 @@
@Attribute(events = @EventName("focus"))
public abstract String getOnfocus();
+
+ @Attribute(events = @EventName("selectitem"))
+ public abstract String getOnselectitem();
- @Attribute(events = @EventName("listblur"))
- public abstract String getOnlistblur();
-
- @Attribute(events = @EventName("listfocus"))
- public abstract String getOnlistfocus();
-
@Attribute(events = @EventName("begin"))
public abstract String getOnbegin();
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-17
07:57:19 UTC (rev 19230)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-09-17
08:01:17 UTC (rev 19231)
@@ -53,6 +53,7 @@
import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.util.InputUtils;
import org.richfaces.renderkit.util.RendererUtils;
+import org.richfaces.renderkit.util.RendererUtils.ScriptHashVariableWrapper;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators;
@@ -97,11 +98,14 @@
utils.addToScriptHash(options, "disabled",
attributes.get("disabled"), "false");
utils.addToScriptHash(options, "selectFirst",
attributes.get("selectFirst"), "true");
utils.addToScriptHash(options, "tokens",
attributes.get("tokens"));
- utils.addToScriptHash(options, "onbegin",
attributes.get("onbegin"));
- utils.addToScriptHash(options, "oncomplete",
attributes.get("oncomplete"));
- utils.addToScriptHash(options, "onerror",
attributes.get("onerror"));
- utils.addToScriptHash(options, "onbeforedomupdate",
attributes.get("onbeforedomupdate"));
- utils.addToScriptHash(options, "onchange",
attributes.get("onchange"));
+ utils.addToScriptHash(options, "onbegin",
attributes.get("onbegin"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "oncomplete",
attributes.get("oncomplete"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onerror",
attributes.get("onerror"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onbeforedomupdate",
attributes.get("onbeforedomupdate"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onchange",
attributes.get("onchange"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onselectitem",
attributes.get("onselectitem"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onfocus",
attributes.get("onfocus"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onblur",
attributes.get("onblur"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
utils.addToScriptHash(options, "filterFunction",
getClientFilterFunction(component));
String mode = (String) attributes.get("mode");
if (mode != null) {
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-17
07:57:19 UTC (rev 19230)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js 2010-09-17
08:01:17 UTC (rev 19231)
@@ -168,7 +168,7 @@
var index = this.items.index(element);
selectItem.call(this, event, index);
} else {
- this.__onChangeValue(event, getSelectedItemValue.call(this));
+ this.__onEnter(event);
rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
this.hide(event);
}
@@ -431,10 +431,9 @@
__onBeforeShow: function (event) {
},
__onEnter: function (event) {
- this.__onChangeValue(event, getSelectedItemValue.call(this));
- //rf.getDomElement(this.fieldId).blur();
- //rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
- //rf.getDomElement(this.fieldId).focus();
+ var value = getSelectedItemValue.call(this);
+ this.__onChangeValue(event, value);
+ this.invokeEvent("selectitem", rf.getDomElement(this.fieldId), event,
value);
},
__onShow: function (event) {
if (this.options.selectFirst) {
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 2010-09-17
07:57:19 UTC (rev 19230)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/AutocompleteBase.js 2010-09-17
08:01:17 UTC (rev 19231)
@@ -77,6 +77,7 @@
inputEventHandlers["click"+this.namespace] = onClick;
inputEventHandlers[($.browser.opera ? "keypress" :
"keydown")+this.namespace] = onKeyDown;
rf.Event.bindById(this.fieldId, inputEventHandlers, this);
+ //inputEventHandlers["change"+this.namespace] = function (event) {if
(this.focused) {event}};
inputEventHandlers = {};
inputEventHandlers["mousedown"+this.namespace] = onSelectMouseDown;
@@ -107,17 +108,29 @@
};
var onFocus = function (event) {
- this.focused = true;
+ if (!this.focused) {
+ this.__focusValue = this.getInputValue();
+ this.focused = true;
+ this.invokeEvent("focus", rf.getDomElement(this.fieldId), event);
+ }
};
var onBlur = function (event) {
if (this.isMouseDown) {
rf.getDomElement(this.fieldId).focus();
this.isMouseDown = false;
- } else if (this.isVisible && !this.isMouseDown) {
- var _this = this;
- this.timeoutId = window.setTimeout(function(){_this.hide();}, 200);
- this.focused=false;
+ } else if (!this.isMouseDown) {
+ if (this.isVisible) {
+ var _this = this;
+ this.timeoutId = window.setTimeout(function(){_this.hide();}, 200);
+ }
+ if (this.focused) {
+ this.focused=false;
+ this.invokeEvent("blur", rf.getDomElement(this.fieldId), event);
+ if (this.__focusValue != this.getInputValue()) {
+ this.invokeEvent("change", rf.getDomElement(this.fieldId), event);
+ }
+ }
}
};
Modified: trunk/ui/input/ui/src/main/templates/autocomplete.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/autocomplete.template.xml 2010-09-17 07:57:19 UTC
(rev 19230)
+++ trunk/ui/input/ui/src/main/templates/autocomplete.template.xml 2010-09-17 08:01:17 UTC
(rev 19231)
@@ -23,8 +23,6 @@
onmouseup="#{component.attributes['onmouseup']}"
onmousedown="#{component.attributes['onmousedown']}"
onmousemove="#{component.attributes['onmousemove']}"
- onblur="#{component.attributes['onblur']}"
- onfocus="#{component.attributes['onfocus']}"
onmouseover="#{component.attributes['onmouseover']}"
onmouseout="#{component.attributes['onmouseout']}"
onkeyup="#{component.attributes['onkeyup']}"
@@ -51,8 +49,6 @@
onmousemove="#{component.attributes['onlistmousemove']}"
onmouseover="#{component.attributes['onlistmouseover']}"
onmouseout="#{component.attributes['onlistmouseout']}"
- onblur="#{component.attributes['onlistblur']}"
- onfocus="#{component.attributes['onlistfocus']}"
onkeyup="#{component.attributes['onlistkeyup']}"
onkeydown="#{component.attributes['onlistkeydown']}"
onkeypress="#{component.attributes['onlistkeypress']}"