Author: pyaschenko
Date: 2010-12-09 10:06:40 -0500 (Thu, 09 Dec 2010)
New Revision: 20482
Modified:
trunk/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml
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
Log:
http://jira.jboss.com/jira/browse/RF-9835
Modified: trunk/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml 2010-12-09
15:00:26 UTC (rev 20481)
+++ trunk/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml 2010-12-09
15:06:40 UTC (rev 20482)
@@ -4,6 +4,7 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:input="http://richfaces.org/input"
+
xmlns:rich="http://richfaces.org/iteration"
xmlns:a4j="http://richfaces.org/a4j">
<f:view contentType="text/html" />
@@ -43,6 +44,20 @@
#{country.name} #{country.iso} #{country.domain}
<a4j:ajax event="change" render="output"/>
</input:autocomplete>
+ <br /><h:outputText value="RF-9835:" /><br />
+ <input:autocomplete id="myAutocomplete1" mode="client"
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
fetchValue="#{country.name}" showButton="true"
+ value = "#{autoCompleteBean.value}" layout="table">
+ <rich:column>
+ <h:outputText value="#{country.name}" />
+ </rich:column>
+ <rich:column>
+ <h:outputText value="#{country.iso}" />
+ </rich:column>
+ <rich:column>
+ <h:outputText value="#{country.domain}" />
+ </rich:column>
+ <a4j:ajax event="change" render="output"/>
+ </input:autocomplete>
<br/><br/>
Your selection: <h:outputText id="output"
value="#{autoCompleteBean.value}"/>
<script type="text/javascript">
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-12-09
15:00:26 UTC (rev 20481)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-12-09
15:06:40 UTC (rev 20482)
@@ -46,14 +46,12 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.component.AbstractAutocomplete;
import org.richfaces.component.AutocompleteLayout;
import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.util.InputUtils;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterators;
-
/**
* @author Nick Belaevski
*/
@@ -196,6 +194,7 @@
if (mode != null && mode.equals("client")) {
List<Object> fetchValues = new ArrayList<Object>();
this.encodeItems(facesContext, component, fetchValues);
+ this.encodeFetchValues(facesContext, component, fetchValues);
} else {
strategy.encodeItemsContainerBegin(facesContext, component);
// TODO: is it needed
@@ -203,6 +202,18 @@
strategy.encodeItemsContainerEnd(facesContext, component);
}
}
+
+ private void encodeFetchValues(FacesContext facesContext, UIComponent component,
List<Object> fetchValues) throws IOException{
+ if (!fetchValues.isEmpty()) {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
+ writer.writeAttribute(HtmlConstants.TYPE_ATTR, "text/javascript",
null);
+ StringBuilder sb = new
StringBuilder("\njQuery(RichFaces.getDomElement('");
+
sb.append(component.getClientId(facesContext)).append("Items')).data({componentData:").append(ScriptUtils.toScript(fetchValues)).append("});\n");
+ writer.write(sb.toString());
+ writer.endElement(HtmlConstants.SCRIPT_ELEM);
+ }
+ }
public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
Object item,
AutocompleteEncodeStrategy strategy) throws IOException {
@@ -282,7 +293,7 @@
encodeItems(context, component, fetchValues);
partialWriter.endUpdate();
- if (!fetchValues.isEmpty() && Iterators.find(fetchValues.iterator(),
Predicates.notNull()) != null) {
+ if (!fetchValues.isEmpty()) {
Map<String, Object> dataMap =
AjaxContext.getCurrentInstance(context).getResponseComponentDataMap();
dataMap.put(component.getClientId(context), fetchValues);
}
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-12-09
15:00:26 UTC (rev 20481)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js 2010-12-09
15:06:40 UTC (rev 20482)
@@ -137,8 +137,6 @@
};
var REGEXP_TRIM = /^[\n\s]*(.*)[\n\s]*$/;
- var REGEXP_TOKEN_LEFT;
- var REGEXP_TOKEN_RIGHT;
var getData = function (nodeList) {
var data = [];
@@ -152,8 +150,8 @@
this.useTokens = (typeof this.options.tokens == "string" &&
this.options.tokens.length>0);
if (this.useTokens) {
var escapedTokens = this.options.tokens.split('').join("\\");
- REGEXP_TOKEN_LEFT = new RegExp('[^'+escapedTokens+']+$','i');
- REGEXP_TOKEN_RIGHT = new RegExp('['+escapedTokens+']','i');
+ this.REGEXP_TOKEN_LEFT = new
RegExp('[^'+escapedTokens+']+$','i');
+ this.REGEXP_TOKEN_RIGHT = new
RegExp('['+escapedTokens+']','i');
this.hasSpaceToken = this.options.tokens.indexOf(' ')!=-1;
};
};
@@ -178,9 +176,12 @@
};
var updateItemsList = function (value, fetchValues) {
- this.items =
$(rf.getDomElement(this.id+ID.ITEMS)).find("."+this.options.itemClass);
+ var itemsContainer = $(rf.getDomElement(this.id+ID.ITEMS));
+ this.items = itemsContainer.find("."+this.options.itemClass);
+ var data = itemsContainer.data();
+ itemsContainer.removeData();
if (this.items.length>0) {
- this.cache = new rf.utils.Cache((this.options.ajaxMode ? value : ""),
this.items, fetchValues || getData, !this.options.ajaxMode);
+ this.cache = new rf.utils.Cache((this.options.ajaxMode ? value : ""),
this.items, fetchValues || data.componentData || getData, !this.options.ajaxMode);
}
};
@@ -353,12 +354,12 @@
var cursorPosition = rf.Selection.getStart(field);
var beforeCursorStr = value.substring(0, cursorPosition);
var afterCursorStr = value.substring(cursorPosition);
- var r = REGEXP_TOKEN_LEFT.exec(beforeCursorStr);
+ var r = this.REGEXP_TOKEN_LEFT.exec(beforeCursorStr);
var result = "";
if (r) {
result = r[0];
}
- r = afterCursorStr.search(REGEXP_TOKEN_RIGHT);
+ r = afterCursorStr.search(this.REGEXP_TOKEN_RIGHT);
if (r==-1) r = afterCursorStr.length;
result += afterCursorStr.substring(0, r);
@@ -376,9 +377,9 @@
var beforeCursorStr = inputValue.substring(0, cursorPosition);
var afterCursorStr = inputValue.substring(cursorPosition);
- var pos = beforeCursorStr.search(REGEXP_TOKEN_LEFT);
+ var pos = beforeCursorStr.search(this.REGEXP_TOKEN_LEFT);
var startPos = pos!=-1 ? pos : beforeCursorStr.length;
- pos = afterCursorStr.search(REGEXP_TOKEN_RIGHT);
+ pos = afterCursorStr.search(this.REGEXP_TOKEN_RIGHT);
var endPos = pos!=-1 ? pos : afterCursorStr.length;
var beginNewValue = inputValue.substring(0, startPos) + value;
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-12-09
15:00:26 UTC (rev 20481)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/AutocompleteBase.js 2010-12-09
15:06:40 UTC (rev 20482)
@@ -198,7 +198,7 @@
this.parentElement = element.parentNode;
$(element).detach().appendTo("body");
}
- $(rf.getDomElement(this.selectId)).setPosition({id: this.fieldId},
{type:"DROPDOWN", offset:[0,20]}).show();
+ $(rf.getDomElement(this.selectId)).setPosition({id: this.fieldId},
{type:"DROPDOWN"}).show();
this.isVisible = true;
this.__onShow(event);
}