Author: ilya_shaikovsky
Date: 2010-08-18 07:46:39 -0400 (Wed, 18 Aug 2010)
New Revision: 18749
Added:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/autocomplete/
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBean.java
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/cachedAjax.xhtml
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/cachedAjax-sample.xhtml
Removed:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/simpleClient-sample.xhtml
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/simpleClient.xhtml
Modified:
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
Log:
https://jira.jboss.org/browse/RF-8871
Added:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBean.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBean.java
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBean.java 2010-08-18
11:46:39 UTC (rev 18749)
@@ -0,0 +1,72 @@
+package org.richfaces.demo.autocomplete;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ManagedProperty;
+import javax.faces.bean.RequestScoped;
+
+import org.richfaces.demo.tables.model.capitals.Capital;
+
+@ManagedBean
+@RequestScoped
+public class AutocompleteBean {
+ private String value;
+ private List<String> autocompleteList;
+ @ManagedProperty(value = "#{capitalsParser.capitalsList}")
+ private List<Capital> capitals;
+
+ public AutocompleteBean() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @PostConstruct
+ public void init() {
+ autocompleteList = new ArrayList<String>();
+ for (Capital cap : capitals) {
+ autocompleteList.add(cap.getState());
+ }
+ }
+
+ public List<String> autocomplete(String prefix) {
+ ArrayList<String> result = new ArrayList<String>();
+ if (prefix.length() > 0) {
+ Iterator<Capital> iterator = capitals.iterator();
+ while (iterator.hasNext()) {
+ Capital elem = ((Capital) iterator.next());
+ if ((elem.getState() != null &&
elem.getState().toLowerCase().indexOf(prefix.toLowerCase()) == 0)
+ || "".equals(prefix)) {
+ result.add(elem.getState());
+ }
+ }
+ }else{
+ for (int i = 0; i < 10; i++) {
+ result.add(capitals.get(i).getState());
+ }
+ }
+ return result;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public List<String> getAutocompleteList() {
+ return autocompleteList;
+ }
+
+ public void setAutocompleteList(List<String> autocompleteList) {
+ this.autocompleteList = autocompleteList;
+ }
+
+ public void setCapitals(List<Capital> capitals) {
+ this.capitals = capitals;
+ }
+}
Modified:
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-08-18
11:18:22 UTC (rev 18748)
+++
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-08-18
11:46:39 UTC (rev 18749)
@@ -346,20 +346,16 @@
<group new="true">
<name>Inputs and Selects</name>
<demos>
- <!-- demo>
+ <demo>
<id>autocomplete</id>
<name>rich:autocomplete</name>
<samples>
<sample>
- <id>simpleClient</id>
- <name>Client side autocomplete</name>
- </sample>
- <sample>
- <id>simpleAjax</id>
- <name>Ajax autocomplete</name>
- </sample>
+ <id>cachedAjax</id>
+ <name>Autocomplete in Cached Ajax mode</name>
+ </sample>
</samples>
- </demo-->
+ </demo>
<demo>
<id>inputNumberSlider</id>
<name>rich:inputNumberSlider</name>
Copied:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/cachedAjax.xhtml
(from rev 18746,
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/simpleClient.xhtml)
===================================================================
---
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/cachedAjax.xhtml
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/cachedAjax.xhtml 2010-08-18
11:46:39 UTC (rev 18749)
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition>
+ <p>Autocomplete component - simple Input component which provides suggestions
during input.</p>
+ <p>Could works using three modes:
+ <ul>
+ <li>Client - preloads data to the client side and makes suggestions according to
entered prefix on the client</li>
+ <li>Ajax - fetches the data on every input change using ajax
requests</li>
+ <li>Cached Ajax - loads data via ajax to make suggestions when the prefix length
satisfies minchars attribute. Then all the suggestions done at client side except the case
when initial prefix changed or token entered. Then loads data again.</li>
+ </ul>
+ </p>
+ <p>Here is the sample for new cachedAjax mode. </p>
+ <ui:include src="#{demoNavigator.sampleIncludeURI}" />
+ <ui:include src="/templates/includes/source-view.xhtml">
+ <ui:param name="src" value="#{demoNavigator.sampleIncludeURI}"
/>
+ <ui:param name="sourceType" value="xhtml" />
+ <ui:param name="openLabel" value="View Source" />
+ <ui:param name="hideLabel" value="Hide Source" />
+ </ui:include>
+</ui:composition>
+
+</html>
\ No newline at end of file
Copied:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/cachedAjax-sample.xhtml
(from rev 18746,
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/simpleClient-sample.xhtml)
===================================================================
---
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/cachedAjax-sample.xhtml
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/cachedAjax-sample.xhtml 2010-08-18
11:46:39 UTC (rev 18749)
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
+
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:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+ <p>Default autocomplete in cachedAjax mode</p>
+ <h:form>
+ <rich:autocomplete mode="cachedAjax"
+ autocompleteMethod="#{autocompleteBean.autocomplete}" />
+ </h:form>
+ <p>Autocomplete without direct suggestions to
input(<b>autoFill="false"</b>). Also in the sample comma and space
are input <b>tokens</b>, so separate
+ autocompletion requests will be fired for different parts in input</p>
+ <h:form>
+ <rich:autocomplete mode="cachedAjax" tokens=", "
autoFill="false"
+ autocompleteMethod="#{autocompleteBean.autocomplete}" />
+ </h:form>
+ <p>In that sample <b>selectFirst</b> set to false so pressing enter
will not choose the value from list
+ but just submit currently entered value.</p>
+ <h:form>
+ <rich:autocomplete mode="cachedAjax" tokens=", "
autoFill="false" selectFirst="false"
+ autocompleteMethod="#{autocompleteBean.autocomplete}" />
+ </h:form>
+ <fieldset>
+ <legend><b>NOTE:</b> </legend>
+ The developer has full control under filtering on server side according to prefix.
+ But in client and cachedAjax modes - just built-in startWith method used. In near
future
+ the component will be updated with one more attribute which will allow the developer
+ to define client side comparator function to customize that behavior.
+ </fieldset>
+</ui:composition>
Deleted:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/simpleClient-sample.xhtml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/simpleClient-sample.xhtml 2010-08-18
11:18:22 UTC (rev 18748)
+++
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/samples/simpleClient-sample.xhtml 2010-08-18
11:46:39 UTC (rev 18749)
@@ -1,11 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
-
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:a4j="http://richfaces.org/a4j"
-
xmlns:rich="http://richfaces.org/rich">
-
-<rich:autocomplete autocompleteList="#{autocompleteBean.clientList}"/>
-
-</ui:composition>
\ No newline at end of file
Deleted:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/simpleClient.xhtml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/simpleClient.xhtml 2010-08-18
11:18:22 UTC (rev 18748)
+++
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/autocomplete/simpleClient.xhtml 2010-08-18
11:46:39 UTC (rev 18749)
@@ -1,26 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets">
-
-<ui:composition>
- <p>Autocomplete component - simple Input component which provides suggestions
during input.</p>
- <p>Could works using three modes:
- <ul>
- <li>Client - preloads data to the client side and makes suggestions according to
entered prefix on the client</li>
- <li>Ajax - fetches the data on every input change using ajax
requests</li>
- <li>Cached Ajax - loads data via ajax to make suggestions when the prefix length
satisfies minchars attribute. Then all the suggestions done at client side except the case
when initial prefix changed or token entered. Then loads data again.</li>
- </ul>
- </p>
- <p>There you could see simple client side autocomplete:</p>
- <ui:include src="#{demoNavigator.sampleIncludeURI}" />
- <ui:include src="/templates/includes/source-view.xhtml">
- <ui:param name="src" value="#{demoNavigator.sampleIncludeURI}"
/>
- <ui:param name="sourceType" value="xhtml" />
- <ui:param name="openLabel" value="View Source" />
- <ui:param name="hideLabel" value="Hide Source" />
- </ui:include>
-</ui:composition>
-
-</html>
\ No newline at end of file