Author: vmolotkov
Date: 2007-12-28 16:00:53 -0500 (Fri, 28 Dec 2007)
New Revision: 5098
Modified:
trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx
Log:
filtering of data was added
Modified:
trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
===================================================================
---
trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2007-12-28
20:57:43 UTC (rev 5097)
+++
trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2007-12-28
21:00:53 UTC (rev 5098)
@@ -12,6 +12,9 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.javascript.ScriptString;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
@@ -97,4 +100,23 @@
Collections.sort(suggestionValues); //FIXME
return ScriptUtils.toScript(suggestionValues);
}
+
+ public String getAsEventHandler(FacesContext context, UIComponent component, String
attributeName) {
+ String event = (String) component.getAttributes().get(attributeName);
+ ScriptString result = JSReference.NULL;
+
+ if (event != null) {
+ event = event.trim();
+
+ if (event.length() != 0) {
+ JSFunctionDefinition function = new JSFunctionDefinition();
+ function.addParameter("event");
+ function.addToBody(event);
+
+ result = function;
+ }
+ }
+
+ return ScriptUtils.toScript(result);
+ }
}
Modified:
trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
===================================================================
---
trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js 2007-12-28
20:57:43 UTC (rev 5097)
+++
trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js 2007-12-28
21:00:53 UTC (rev 5098)
@@ -3,15 +3,19 @@
Richfaces.ComboBox.prototype = {
- initialize: function(combobox, listId, fieldId, buttonId, classes, listWidth,
listHeight, itemsText, directInputSuggestions, filterNewValue) {
+ initialize: function(combobox, listId, fieldId, buttonId, classes, listWidth,
listHeight, itemsText, directInputSuggestions, filterNewValue, onlistcall, onselected,
defaultMessage) {
this.directInputSuggestions = directInputSuggestions;
this.filterNewValue = filterNewValue;
this.combobox = $(combobox);
- this.comboList = new Richfaces.ComboBoxList(listId, classes, listWidth, listHeight,
itemsText);
+ this.comboList = new Richfaces.ComboBoxList(listId, classes, listWidth, listHeight,
itemsText, onlistcall);
this.field = $(fieldId);
this.button = $(buttonId);
+ this.defaultMessage = defaultMessage;
+
+ this.onselected = onselected;
+
this.initCombobox();
},
@@ -23,6 +27,10 @@
this.comboList.listParent.observe("mousemove",
function(e){this.listListener(e)}.bindAsEventListener(this));
this.comboList.listParent.observe("click",
function(e){this.valueHandler(e);}.bindAsEventListener(this));
+
+ if (this.onselected) {
+ this.combobox.observe("rich:onselected", this.onselected);
+ }
},
clickHandler : function(event) {
@@ -44,7 +52,7 @@
},
valueHandler : function(event) {
- this.setValue();
+ this.setValue(true);
this.comboList.hide();
},
@@ -53,6 +61,7 @@
var value = this.comboList.selectedItem.innerHTML;
if (toSetOnly) {
this.field.value = value;
+ this.combobox.fire("rich:onselected", {});
} else {
if (this.directInputSuggestions) {
var startInd = this.field.value.length;
@@ -64,16 +73,6 @@
},
keyboardManager : function(event) {
- /*if ((event.keyCode == Event.KEY_UP) || (event.keyCode == Event.KEY_DOWN)) {
- this.comboList.moveSelectedItem(event);
- } else if (event.keyCode == Event.KEY_RETURN) {
- this.setValue(true);
- this.comboList.hide();
- Event.stop(event);
- } else if (event.keyCode == Event.KEY_BACKSPACE) {
- this.comboList.hide();
- }*/
-
switch (event.keyCode) {
case Event.KEY_RETURN :
this.setValue(true);
@@ -96,6 +95,9 @@
focusHandler : function(event) {
this.comboList.hide();
+ if (this.field.value == "") {
+ this.field.value = this.defaultMessage;
+ }
},
dataUpdating : function(event) {
@@ -104,7 +106,14 @@
this.comboList.dataFilter(this.field.value);
this.comboList.show();
} else {
- //TODO
+ if (!this.comboList.visible()) {
+ this.comboList.show();
+ }
+ var item = this.comboList.findItemByText(this.field.value);
+ if (item) {
+ this.comboList.selectItem(this.comboList.findItemByText(this.field.value));
+ this.comboList.scrollingUpToSdItem();
+ }
}
if (event.keyCode != Event.KEY_BACKSPACE ) {
@@ -117,14 +126,18 @@
Richfaces.ComboBoxList = Class.create();
Richfaces.ComboBoxList.prototype = {
- initialize: function(listId, classes, width, height, itemsText) {
+ initialize: function(listId, classes, width, height, itemsText, onlistcall) {
this.list = $(listId);
this.listParent = this.list.parentNode;
this.itemsText = itemsText;
- //this.items = this.getItems();
+ this.onlistcall = onlistcall;
+ if (this.onlistcall) {
+ this.listParent.observe("rich:onlistcall", this.onlistcall);
+ }
+
this.classes = classes;
this.selectedItem = null;
@@ -150,6 +163,8 @@
this.selectItem(curItems[0]);
}
this.listParent.show();
+ this.listParent.fire("rich:onlistcall", {});
+
},
hide : function() {
@@ -187,6 +202,11 @@
Event.stop(event);
},
+ scrollingUpToSdItem : function() {
+ var increment = (Richfaces.ComboBoxList.getElemXY(this.selectedItem).top -
this.listParent.scrollTop) - Richfaces.ComboBoxList.getElemXY(this.listParent).top;
+ this.listParent.scrollTop += increment;
+ },
+
/* items library*/
selectItem : function(item) {
if (this.selectedItem) {
@@ -258,6 +278,15 @@
return items;
},
+ findItemByText : function(text) {
+ for (var i = 0; i < this.itemsText.length; i++) {
+ var itText = this.itemsText[i];
+ if (itText.substr(0, text.length).toLowerCase() == text.toLowerCase()) { //FIXME: to
optimaize
+ return this.list.childNodes[i];
+ }
+ }
+ },
+
createNewList : function(items) {
//TODO: write code for IE
var tempList = this.list.cloneNode(false);
Modified: trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx
===================================================================
--- trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx 2007-12-28 20:57:43 UTC
(rev 5097)
+++ trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx 2007-12-28 21:00:53 UTC
(rev 5098)
@@ -37,6 +37,8 @@
"list#{clientId}",
"comboboxField#{clientId}",
"comboboxButton#{clientId}", Richfaces.ComboBoxList.CLASSES, 100,
150,
- #{this:getItemsTextAsJSArray(context, component)}, true, true);
+ #{this:getItemsTextAsJSArray(context, component)}, false, false,
+ #{this:getAsEventHandler(context, component, "onlistcall")},
+ #{this:getAsEventHandler(context, component, "onselected")});
</script>
</f:root>
\ No newline at end of file