JBoss Rich Faces SVN: r22662 - in modules/tests/metamer/trunk/application/src/main: webapp/components/richAutocomplete and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: jjamrich
Date: 2011-08-18 16:31:01 -0400 (Thu, 18 Aug 2011)
New Revision: 22662
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/fetchValueAttr.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/jsr303.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/list.xhtml
Log:
RFPL-1421 and RFPL-1601: add @fetchValue attr for autocomplete, and add suggestions for jsr303 validations
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java 2011-08-18 14:38:05 UTC (rev 22661)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java 2011-08-18 20:31:01 UTC (rev 22662)
@@ -83,6 +83,14 @@
ajaxAttributes = Attributes.getEmptyAttributes(getClass());
ajaxAttributes.setAttribute("render", "output");
ajaxAttributes.setAttribute("execute", "autocomplete");
+
+ attributes.remove("var"); // this attr is supposed to be used with @fetchValue, and cannot be changed
+
+ // since this bean is session scoped, valueX should be reset explicitly
+ value1 = null;
+ value2 = null;
+ value3 = null;
+ value4 = null;
}
public Attributes getAttributes() {
@@ -119,6 +127,35 @@
}
return result;
}
+
+ /**
+ * Since @fetchValue introduced to rich:autocomplete component,
+ * there is possible to serve objects instead of simple string,
+ * and provide more flexible UI
+ *
+ * With @fetchValue is possible display additional information,
+ * even the letters typed into autocomplete input are different
+ * @param prefix
+ * @return List<Capital> with matching prefix
+ */
+ public List<Capital> autocompleteCapital(String prefix) {
+ ArrayList<Capital> result = new ArrayList<Capital>();
+ if (prefix != null && 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);
+ }
+ }
+ } else {
+ for (Capital capital : capitals) {
+ result.add(capital);
+ }
+ }
+ return result;
+ }
public void setCapitals(List<Capital> capitals) {
this.capitals = capitals;
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/fetchValueAttr.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/fetchValueAttr.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/fetchValueAttr.xhtml 2011-08-18 20:31:01 UTC (rev 22662)
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!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" xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
+ xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="component">
+ <rich:autocomplete id="autocomplete"
+ autofill="#{richAutocompleteBean.attributes['autofill'].value}"
+ autocompleteMethod="#{richAutocompleteBean.autocompleteCapital}"
+ clientFilterFunction="#{richAutocompleteBean.attributes['clientFilterFunction'].value}"
+ converterMessage="#{richAutocompleteBean.attributes['converterMessage'].value}"
+ disabled="#{richAutocompleteBean.attributes['disabled'].value}"
+ filterFunction="#{richAutocompleteBean.attributes['filterFunction'].value}"
+ fetchValue="#{capital.state}"
+ immediate="#{richAutocompleteBean.attributes['immediate'].value}"
+ inputClass="#{richAutocompleteBean.attributes['inputClass'].value}"
+ layout="#{richAutocompleteBean.attributes['layout'].value}"
+ minChars="#{richAutocompleteBean.attributes['minChars'].value}"
+ mode="#{richAutocompleteBean.attributes['mode'].value}"
+ onbeforedomupdate="#{richAutocompleteBean.attributes['onbeforedomupdate'].value}"
+ onbegin="#{richAutocompleteBean.attributes['onbegin'].value}"
+ onblur="#{richAutocompleteBean.attributes['onblur'].value}"
+ onchange="#{richAutocompleteBean.attributes['onchange'].value}"
+ onclick="#{richAutocompleteBean.attributes['onclick'].value}"
+ oncomplete="#{richAutocompleteBean.attributes['oncomplete'].value}"
+ ondblclick="#{richAutocompleteBean.attributes['ondblclick'].value}"
+ onerror="#{richAutocompleteBean.attributes['onerror'].value}"
+ onfocus="#{richAutocompleteBean.attributes['onfocus'].value}"
+ onkeydown="#{richAutocompleteBean.attributes['onkeydown'].value}"
+ onkeypress="#{richAutocompleteBean.attributes['onkeypress'].value}"
+ onkeyup="#{richAutocompleteBean.attributes['onkeyup'].value}"
+ onlistclick="#{richAutocompleteBean.attributes['onlistclick'].value}"
+ onlistdblclick="#{richAutocompleteBean.attributes['onlistdblclick'].value}"
+ onlistkeydown="#{richAutocompleteBean.attributes['onlistkeydown'].value}"
+ onlistkeypress="#{richAutocompleteBean.attributes['onlistkeypress'].value}"
+ onlistkeyup="#{richAutocompleteBean.attributes['onlistkeyup'].value}"
+ onlistmousedown="#{richAutocompleteBean.attributes['onlistmousedown'].value}"
+ onlistmousemove="#{richAutocompleteBean.attributes['onlistmousemove'].value}"
+ onlistmouseout="#{richAutocompleteBean.attributes['onlistmouseout'].value}"
+ onlistmouseover="#{richAutocompleteBean.attributes['onlistmouseover'].value}"
+ onlistmouseup="#{richAutocompleteBean.attributes['onlistmouseup'].value}"
+ onmousedown="#{richAutocompleteBean.attributes['onmousedown'].value}"
+ onmousemove="#{richAutocompleteBean.attributes['onmousemove'].value}"
+ onmouseout="#{richAutocompleteBean.attributes['onmouseout'].value}"
+ onmouseover="#{richAutocompleteBean.attributes['onmouseover'].value}"
+ onmouseup="#{richAutocompleteBean.attributes['onmouseup'].value}"
+ onselectitem="#{richAutocompleteBean.attributes['onselectitem'].value}"
+ popupClass="#{richAutocompleteBean.attributes['popupClass'].value}"
+ rendered="#{richAutocompleteBean.attributes['rendered'].value}"
+ required="#{richAutocompleteBean.attributes['required'].value}"
+ requiredMessage="#{richAutocompleteBean.attributes['requiredMessage'].value}"
+ selectFirst="#{richAutocompleteBean.attributes['selectFirst'].value}"
+ selectedItemClass="#{richAutocompleteBean.attributes['selectedItemClass'].value}"
+ showButton="#{richAutocompleteBean.attributes['showButton'].value}"
+ tokens="#{richAutocompleteBean.attributes['tokens'].value}"
+ validatorMessage="#{richAutocompleteBean.attributes['validatorMessage'].value}"
+ value="#{richAutocompleteBean.attributes['value'].value}"
+ valueChangeListener="#{richBean.valueChangeListener}"
+ var="capital"
+ >
+
+ <rich:column>
+ <h:outputText value="#{capital.state}" />
+ </rich:column>
+ <rich:column>
+ [<h:outputText value="#{capital.name}" />]
+ </rich:column>
+
+ <a4j:ajax event="change"
+ render="#{richAutocompleteBean.ajaxAttributes['render'].value}"
+ execute="#{richAutocompleteBean.ajaxAttributes['execute'].value}"
+ listener="#{richBean.changeEventListener}" />
+
+ <a4j:ajax event="selectitem" render="output"
+ listener="#{richBean.actionListener}"
+ />
+
+ </rich:autocomplete>
+
+ <br/><br/>
+ Your selection: <h:outputText id="output" value="#{richAutocompleteBean.attributes['value'].value}"/>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richAutocompleteBean.attributes}" id="attributes" />
+ <metamer:attributes value="#{richAutocompleteBean.ajaxAttributes}" id="ajaxAttributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/jsr303.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/jsr303.xhtml 2011-08-18 14:38:05 UTC (rev 22661)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/jsr303.xhtml 2011-08-18 20:31:01 UTC (rev 22662)
@@ -42,14 +42,17 @@
<h:panelGrid columns="3">
not empty
- <rich:autocomplete id="input1" value="#{richAutocompleteBean.value1}" >
+ <rich:autocomplete id="input1"
+ autocompleteMethod="#{richAutocompleteBean.autocomplete}"
+ value="#{richAutocompleteBean.value1}"
+ >
<a4j:ajax event="change" render="output1"/>
</rich:autocomplete>
<rich:message id="inputMsg1" for="input1"/>
pattern [a-z].*
<rich:autocomplete id="input2"
- defaultLabel="#{richAutocompleteBean.attributes['defaultLabel'].value}"
+ autocompleteMethod="#{richAutocompleteBean.autocomplete}"
value="#{richAutocompleteBean.value2}"
>
<a4j:ajax event="change" render="output2"/>
@@ -58,7 +61,7 @@
size 3-6
<rich:autocomplete id="input3"
- defaultLabel="#{richAutocompleteBean.attributes['defaultLabel'].value}"
+ autocompleteMethod="#{richAutocompleteBean.autocomplete}"
value="#{richAutocompleteBean.value3}"
>
<a4j:ajax event="change" render="output3"/>
@@ -66,9 +69,8 @@
<rich:message id="inputMsg3" for="input3"/>
custom (RichFaces)
- <rich:autocomplete id="input4"
- defaultLabel="#{richAutocompleteBean.attributes['defaultLabel'].value}"
- value="#{richAutocompleteBean.value4}"
+ <rich:autocomplete id="input4"
+ value="#{richAutocompleteBean.value4}"
>
<f:validator validatorId="org.richfaces.StringRichFacesValidator"/>
<a4j:ajax event="change" render="output4"/>
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/list.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/list.xhtml 2011-08-18 14:38:05 UTC (rev 22661)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richAutocomplete/list.xhtml 2011-08-18 20:31:01 UTC (rev 22662)
@@ -36,6 +36,10 @@
input boxes for all its attributes.
</metamer:testPageLink>
+ <metamer:testPageLink id="fetchValueAttr" outcome="fetchValueAttr" value="Formatted suggestions">
+ Simple page that contains <b>rich:autocomplete</b> with example of use @fetchValue (suggestions formatting)
+ </metamer:testPageLink>
+
<metamer:testPageLink id="jsr303" outcome="jsr303" value="JSR-303 Bean Validation">
Simple page that contains some <b>rich:autocomplete</b>s with various JSR-303 validators.
</metamer:testPageLink>