[richfaces-svn-commits] JBoss Rich Faces SVN: r18631 - in sandbox/trunk/ui/inputs/combobox: src/main/java/org/richfaces/component and 5 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Fri Aug 13 13:34:19 EDT 2010
Author: amarkhel
Date: 2010-08-13 13:34:18 -0400 (Fri, 13 Aug 2010)
New Revision: 18631
Added:
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractAutoComplete.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AbstractAutocompleteLayoutStrategy.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteEncodeStrategy.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteRendererBase.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteBaseGradient.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteButtonGradient.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteFieldGradient.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/AutoCompleteHandler.java
Removed:
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxBaseGradient.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxButtonGradient.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxFieldGradient.java
sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java
Modified:
sandbox/trunk/ui/inputs/combobox/pom.xml
sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss
sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js
sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js
sandbox/trunk/ui/inputs/combobox/src/main/templates/comboBox.template.xml
Log:
Implement server-side code for autocomplete component
Modified: sandbox/trunk/ui/inputs/combobox/pom.xml
===================================================================
--- sandbox/trunk/ui/inputs/combobox/pom.xml 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/pom.xml 2010-08-13 17:34:18 UTC (rev 18631)
@@ -28,8 +28,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.richfaces.ui.inputs-sandbox</groupId>
- <artifactId>combobox</artifactId>
- <name>Richfaces UI Sandbox Components: ComboBox Input Component</name>
+ <artifactId>autocomplete</artifactId>
+ <name>Richfaces UI Sandbox Components: AutoComplete Input Component</name>
<packaging>jar</packaging>
<build>
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractAutoComplete.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractAutoComplete.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractAutoComplete.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,261 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.util.ELUtils;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Signature;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.component.MetaComponentEncoder;
+import org.richfaces.component.MetaComponentResolver;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.renderkit.MetaComponentRenderer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+ at JsfComponent(tag = @Tag(type = TagType.Facelets, handler = "org.richfaces.view.facelets.AutoCompleteHandler"),
+ renderer = @JsfRenderer(type = "org.richfaces.AutoCompleteRenderer")
+)
+public abstract class AbstractAutoComplete extends UIInput implements MetaComponentResolver, MetaComponentEncoder {
+
+ public static final String ITEMS_META_COMPONENT_ID = "items";
+
+ public static final String COMPONENT_TYPE = "org.richfaces.AutoComplete";
+
+ public static final String COMPONENT_FAMILY = UIInput.COMPONENT_FAMILY;
+
+ //TODO nick - change to Object - https://jira.jboss.org/browse/RF-8897
+ public abstract Object getAutocompleteList();
+
+ @Attribute(signature = @Signature(returnType = Object.class, parameters = { FacesContext.class, UIComponent.class,
+ String.class }))
+ public abstract MethodExpression getAutocompleteMethod();
+ public abstract void setAutocompleteMethod(MethodExpression expression);
+ public abstract void setItemConverter(Converter converter);
+ @Attribute(literal = true)
+ public abstract String getVar();
+
+ //TODO nick - el-only?
+ @Attribute(literal = false)
+ public abstract Object getFetchValue();
+
+ @Attribute(defaultValue = "1")
+ public abstract int getMinChars();
+
+ @Attribute
+ public abstract String getFilterFunction();
+
+ @Attribute
+ public abstract String getMode();
+
+ @Attribute
+ public abstract String getLayout();
+
+ @Attribute
+ public abstract Converter getItemConverter();
+
+ @Attribute(defaultValue = "false")
+ public abstract boolean isAutoFill();
+
+ @Attribute(defaultValue = "false")
+ public abstract boolean isDisabled();
+
+ @Attribute(defaultValue = "false")
+ public abstract boolean isShowButton();
+
+ @Attribute(defaultValue = "false")
+ public abstract boolean isSelectFirst();
+
+ @Attribute(events = @EventName("click"))
+ public abstract String getOnclick();
+
+ @Attribute(events = @EventName("dblclick"))
+ public abstract String getOndblclick();
+
+ @Attribute(events = @EventName("mousedown"))
+ public abstract String getOnmousedown();
+
+ @Attribute(events = @EventName("mouseup"))
+ public abstract String getOnmouseup();
+
+ @Attribute(events = @EventName("mouseover"))
+ public abstract String getOnmouseover();
+
+ @Attribute(events = @EventName("mousemove"))
+ public abstract String getOnmousemove();
+
+ @Attribute(events = @EventName("mouseout"))
+ public abstract String getOnmouseout();
+
+ @Attribute(events = @EventName("keypress"))
+ public abstract String getOnkeypress();
+
+ @Attribute(events = @EventName("keydown"))
+ public abstract String getOnkeydown();
+
+ @Attribute(events = @EventName("keyup"))
+ public abstract String getOnkeyup();
+
+ @Attribute(events = @EventName("listclick"))
+ public abstract String getOnlistclick();
+
+ @Attribute(events = @EventName("listdblclick"))
+ public abstract String getOnlistdblclick();
+
+ @Attribute(events = @EventName("listmousedown"))
+ public abstract String getOnlistmousedown();
+
+ @Attribute(events = @EventName("listmouseup"))
+ public abstract String getOnlistmouseup();
+
+ @Attribute(events = @EventName("listmouseover"))
+ public abstract String getOnlistmouseover();
+
+ @Attribute(events = @EventName("listmousemove"))
+ public abstract String getOnlistmousemove();
+
+ @Attribute(events = @EventName("listmouseout"))
+ public abstract String getOnlistmouseout();
+
+ @Attribute(events = @EventName("listkeypress"))
+ public abstract String getOnlistkeypress();
+
+ @Attribute(events = @EventName("listkeydown"))
+ public abstract String getOnlistkeydown();
+
+ @Attribute(events = @EventName("listkeyup"))
+ public abstract String getOnlistkeyup();
+
+ @Attribute(events = @EventName("change"))
+ public abstract String getOnchange();
+
+ @Attribute(events = @EventName("blur"))
+ public abstract String getOnblur();
+
+ @Attribute(events = @EventName("focus"))
+ public abstract String getOnfocus();
+
+ @Attribute(events = @EventName("listblur"))
+ public abstract String getOnlistblur();
+
+ @Attribute(events = @EventName("listfocus"))
+ public abstract String getOnlistfocus();
+
+ @Attribute(events = @EventName("begin"))
+ public abstract String getOnbegin();
+
+ @Attribute(events = @EventName("error"))
+ public abstract String getOnerror();
+
+ @Attribute(events = @EventName("complete"))
+ public abstract String getOncomplete();
+
+ @Attribute(events = @EventName("beforedomupdate"))
+ public abstract String getOnbeforedomupdate();
+
+ @Override
+ public Converter getConverter() {
+
+ Converter converter = super.getConverter();
+ if(converter == null) {
+ converter = getConverterForValue(FacesContext.getCurrentInstance());
+ }
+
+ return converter;
+ }
+
+ private Converter getConverterForType(FacesContext context, Class <?> type) {
+
+ if (!Object.class.equals(type) && type != null) {
+ Application application = context.getApplication();
+ return application.createConverter(type);
+ }
+
+ return null;
+ }
+
+ public Converter getConverterForValue(FacesContext context) {
+ Converter converter = null;
+ ValueExpression expression = this.getValueExpression("value");
+
+ if (expression != null) {
+ Class<?> containerClass = ELUtils.getContainerClass(context, expression);
+
+ converter = getConverterForType(context, containerClass);
+ }
+
+ return converter;
+ }
+
+ public String resolveClientId(FacesContext facesContext, UIComponent contextComponent, String metaComponentId) {
+ if (ITEMS_META_COMPONENT_ID.equals(metaComponentId)) {
+ return getClientId(facesContext) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean visitTree(VisitContext context, VisitCallback callback) {
+ if (context instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) context;
+ if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER) {
+
+ VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this, callback, ITEMS_META_COMPONENT_ID);
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ } else if (result == VisitResult.REJECT) {
+ return false;
+ }
+ }
+ }
+
+ return super.visitTree(context, callback);
+ }
+
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this, metaComponentId);
+ }
+}
Deleted: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/component/AbstractComboBox.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -1,104 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- */
-package org.richfaces.component;
-
-import java.io.IOException;
-import java.util.List;
-
-import javax.el.MethodExpression;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
-import javax.faces.component.visit.VisitCallback;
-import javax.faces.component.visit.VisitContext;
-import javax.faces.component.visit.VisitResult;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.cdk.annotations.Attribute;
-import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.Signature;
-import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.cdk.annotations.TagType;
-import org.richfaces.context.ExtendedVisitContext;
-import org.richfaces.context.ExtendedVisitContextMode;
-import org.richfaces.renderkit.MetaComponentRenderer;
-
-/**
- * @author Nick Belaevski
- *
- */
- at JsfComponent(tag = @Tag(type = TagType.Facelets, handler = "org.richfaces.view.facelets.ComboBoxHandler"),
- renderer = @JsfRenderer(type = "org.richfaces.ComboBoxRenderer")
-)
-public abstract class AbstractComboBox extends UIInput implements MetaComponentResolver, MetaComponentEncoder {
-
- public static final String ITEMS_META_COMPONENT_ID = "items";
-
- public static final String COMPONENT_TYPE = "org.richfaces.ComboBox";
-
- public static final String COMPONENT_FAMILY = UIInput.COMPONENT_FAMILY;
-
- //TODO nick - change to Object - https://jira.jboss.org/browse/RF-8897
- public abstract List<?> getAutocompleteList();
-
- @Attribute(signature = @Signature(returnType = Object.class, parameters = { FacesContext.class, UIComponent.class,
- String.class }))
- public abstract MethodExpression getAutocompleteMethod();
- public abstract void setAutocompleteMethod(MethodExpression expression);
-
- @Attribute(literal = true)
- public abstract String getVar();
-
- //TODO nick - el-only?
- @Attribute(literal = false)
- public abstract Object getFetchValue();
-
- public String resolveClientId(FacesContext facesContext, UIComponent contextComponent, String metaComponentId) {
- if (ITEMS_META_COMPONENT_ID.equals(metaComponentId)) {
- return getClientId(facesContext) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
- }
-
- return null;
- }
-
- @Override
- public boolean visitTree(VisitContext context, VisitCallback callback) {
- if (context instanceof ExtendedVisitContext) {
- ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) context;
- if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER) {
-
- VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this, callback, ITEMS_META_COMPONENT_ID);
- if (result == VisitResult.COMPLETE) {
- return true;
- } else if (result == VisitResult.REJECT) {
- return false;
- }
- }
- }
-
- return super.visitTree(context, callback);
- }
-
- public void encodeMetaComponent(FacesContext context, String metaComponentId) throws IOException {
- ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this, metaComponentId);
- }
-}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AbstractAutocompleteLayoutStrategy.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AbstractAutocompleteLayoutStrategy.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AbstractAutocompleteLayoutStrategy.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,10 @@
+package org.richfaces.renderkit;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+public class AbstractAutocompleteLayoutStrategy {
+ public String getContainerElementId(FacesContext facesContext, UIComponent component) {
+ return component.getClientId(facesContext) + "Items";
+ }
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteEncodeStrategy.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteEncodeStrategy.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteEncodeStrategy.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,22 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.AbstractAutoComplete;
+
+
+public interface AutoCompleteEncodeStrategy {
+ void encodeItemsContainerBegin(FacesContext facesContext, UIComponent component) throws IOException ;
+
+ void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException ;
+
+ void encodeFakeItem(FacesContext facesContext, UIComponent component) throws IOException ;
+
+ void encodeItem(FacesContext facesContext, AbstractAutoComplete comboBox,
+ Object nextItem) throws IOException;
+
+ public String getContainerElementId(FacesContext facesContext, UIComponent component);
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteRendererBase.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteRendererBase.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutoCompleteRendererBase.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,284 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialResponseWriter;
+import javax.faces.context.PartialViewContext;
+import javax.faces.model.ArrayDataModel;
+import javax.faces.model.DataModel;
+import javax.faces.model.ListDataModel;
+import javax.faces.model.ResultDataModel;
+import javax.faces.model.ResultSetDataModel;
+import javax.servlet.jsp.jstl.sql.Result;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.util.InputUtils;
+import org.richfaces.component.AbstractAutoComplete;
+import org.richfaces.component.AutocompleteLayout;
+import org.richfaces.component.MetaComponentResolver;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+ at ResourceDependencies( {
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "jquery.position.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-event.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(name = "richfaces-selection.js"),
+ @ResourceDependency(library = "org.richfaces", name = "AutoCompleteBase.js"),
+ @ResourceDependency(library = "org.richfaces", name = "AutoComplete.js"),
+ @ResourceDependency(library = "org.richfaces", name = "AutoComplete.ecss")
+
+})
+public abstract class AutoCompleteRendererBase extends InputRendererBase implements
+ MetaComponentRenderer {
+
+ public String getScriptOptions(UIComponent component){
+ Map<String, Object> attributes = component.getAttributes();
+ Map<String, Object> options = new HashMap<String, Object>();
+ RendererUtils utils = getUtils();
+ utils.addToScriptHash(options, "buttonId", component.getClientId() + "Button");
+ utils.addToScriptHash(options, "selectedItemClass", "cb_select");
+ utils.addToScriptHash(options, "minChars", attributes.get("minChars"), "1");
+ utils.addToScriptHash(options, "mode", attributes.get("mode"), "ajax");
+ utils.addToScriptHash(options, "filterFunction", attributes.get("filterFunction"));
+ utils.addToScriptHash(options, "autoFill", attributes.get("autoFill"), "false");
+ utils.addToScriptHash(options, "disabled", attributes.get("disabled"), "false");
+ utils.addToScriptHash(options, "selectFirst", attributes.get("selectFirst"), "false");
+ 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"));
+ StringBuilder builder = new StringBuilder();
+ builder.append(ScriptUtils.toScript(options));
+ return builder.toString();
+ }
+ // TODO nick - handle parameter
+ @SuppressWarnings("unchecked")
+ private DataModel<Object> getItems(FacesContext facesContext,
+ AbstractAutoComplete component) {
+ Object itemsObject = null;
+
+ MethodExpression autocompleteMethod = component.getAutocompleteMethod();
+ if (autocompleteMethod != null) {
+ Map<String, String> requestParameters = facesContext
+ .getExternalContext().getRequestParameterMap();
+ String value = requestParameters.get(component
+ .getClientId(facesContext)
+ + "Value");
+ try {
+ // String value = getInputValue(facesContext, component);
+
+ itemsObject = autocompleteMethod.invoke(facesContext
+ .getELContext(), new Object[] { facesContext,
+ component, value });
+ } catch (ELException e) {
+ try {
+ autocompleteMethod = facesContext.getApplication()
+ .getExpressionFactory().createMethodExpression(
+ facesContext.getELContext(),
+ autocompleteMethod.getExpressionString(),
+ Void.class, new Class[] { String.class });
+ itemsObject = autocompleteMethod.invoke(facesContext
+ .getELContext(), new Object[] { value });
+ } catch (ELException ee) {
+ ee.printStackTrace();
+ }
+
+ }
+ } else {
+ itemsObject = component.getAutocompleteList();
+ }
+
+ DataModel result;
+
+ if (itemsObject instanceof Object[]) {
+ result = new ArrayDataModel((Object[]) itemsObject);
+ } else if (itemsObject instanceof List) {
+ result = new ListDataModel((List<Object>) itemsObject);
+ } else if (itemsObject instanceof Result) {
+ result = new ResultDataModel((Result) itemsObject);
+ } else if (itemsObject instanceof ResultSet) {
+ result = new ResultSetDataModel((ResultSet) itemsObject);
+ } else if (itemsObject != null) {
+ List<Object> temp = new ArrayList<Object>();
+ Iterator<Object> iterator = ((Iterable<Object>) itemsObject)
+ .iterator();
+ while (iterator.hasNext()) {
+ temp.add(iterator.next());
+ }
+ result = new ListDataModel(temp);
+ } else {
+ result = new ListDataModel(null);
+ }
+
+ return result;
+ }
+
+ private Object saveVar(FacesContext context, String var) {
+ if (var != null) {
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ return requestMap.get(var);
+ }
+
+ return null;
+ }
+
+ private void setVar(FacesContext context, String var, Object varObject) {
+ if (var != null) {
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ requestMap.put(var, varObject);
+ }
+ }
+
+ protected void encodeItems(FacesContext facesContext,
+ UIComponent component, List<Object> fetchValues) throws IOException {
+ AbstractAutoComplete comboBox = (AbstractAutoComplete) component;
+ AutoCompleteEncodeStrategy strategy = getStrategy(component);
+ strategy.encodeItemsContainerBegin(facesContext, component);
+
+ boolean hasEncodedElements = false;
+
+ Object savedVar = saveVar(facesContext, comboBox.getVar());
+ DataModel<Object> model = getItems(facesContext, comboBox);
+ for (Iterator<Object> items = model.iterator(); items.hasNext();) {
+ hasEncodedElements = true;
+
+ Object nextItem = items.next();
+ setVar(facesContext, comboBox.getVar(), nextItem);
+
+ strategy.encodeItem(facesContext, comboBox, nextItem);
+ if (comboBox.getFetchValue() != null) {
+ fetchValues.add(comboBox.getFetchValue());
+ } else {
+ //TODO use converter
+ fetchValues.add(nextItem);
+ }
+ }
+
+ setVar(facesContext, comboBox.getVar(), savedVar);
+
+ if (!hasEncodedElements) {
+ strategy.encodeFakeItem(facesContext, component);
+ }
+
+ strategy.encodeItemsContainerEnd(facesContext, component);
+ }
+
+ protected void encodeItemsContainer(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ AutoCompleteEncodeStrategy strategy = getStrategy(component);
+ strategy.encodeItemsContainerBegin(facesContext, component);
+ strategy.encodeFakeItem(facesContext, component);
+ strategy.encodeItemsContainerEnd(facesContext, component);
+ }
+
+ private AutoCompleteEncodeStrategy getStrategy(UIComponent component) {
+ AbstractAutoComplete comboBox = (AbstractAutoComplete) component;
+ if (comboBox.getLayout() != null) {
+ if (comboBox.getLayout().equals(AutocompleteLayout.div)) {
+ return new AutocompleteDivLayoutStrategy();
+ }
+ if (comboBox.getLayout().equals(AutocompleteLayout.grid)) {
+ return new AutocompleteGridLayoutStrategy();
+ }
+ if (comboBox.getLayout().equals(AutocompleteLayout.list)) {
+ return new AutocompleteListLayoutStrategy();
+ }
+ if (comboBox.getLayout().equals(AutocompleteLayout.table)) {
+ return new AutocompleteTableLayoutStrategy();
+ }
+ }
+ return new AutocompleteDivLayoutStrategy();
+ }
+
+ @Override
+ protected void doDecode(FacesContext context, UIComponent component) {
+ if (InputUtils.isDisabled(component)) {
+ return;
+ }
+ super.doDecode(context, component);
+
+ Map<String, String> requestParameters = context.getExternalContext()
+ .getRequestParameterMap();
+ if (requestParameters.get(component.getClientId(context) + ".ajax") != null) {
+ PartialViewContext pvc = context.getPartialViewContext();
+ pvc
+ .getRenderIds()
+ .add(
+ component.getClientId(context)
+ + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
+ + AbstractAutoComplete.ITEMS_META_COMPONENT_ID);
+ }
+ }
+
+ public void encodeMetaComponent(FacesContext context,
+ UIComponent component, String metaComponentId) throws IOException {
+ if (AbstractAutoComplete.ITEMS_META_COMPONENT_ID.equals(metaComponentId)) {
+
+ List<Object> fetchValues = new ArrayList<Object>();
+
+ PartialResponseWriter partialWriter = context
+ .getPartialViewContext().getPartialResponseWriter();
+ partialWriter.startUpdate(getStrategy(component)
+ .getContainerElementId(context, component));
+ encodeItems(context, component, fetchValues);
+ partialWriter.endUpdate();
+
+ if (!fetchValues.isEmpty()
+ && Iterators.find(fetchValues.iterator(), Predicates
+ .notNull()) != null) {
+ Map<String, Object> dataMap = AjaxContext.getCurrentInstance(
+ context).getResponseComponentDataMap();
+ dataMap.put(component.getClientId(context), fetchValues);
+ }
+ } else {
+ throw new IllegalArgumentException(metaComponentId);
+ }
+ }
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,74 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.ajax4jsf.util.InputUtils;
+import org.richfaces.component.AbstractAutoComplete;
+
+public class AutocompleteDivLayoutStrategy extends
+ AbstractAutocompleteLayoutStrategy implements
+ AutoCompleteEncodeStrategy {
+
+ public void encodeFakeItem(FacesContext facesContext, UIComponent component)
+ throws IOException {
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.DIV_ELEM, component);
+ responseWriter.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none",
+ null);
+ responseWriter.endElement(HTML.DIV_ELEM);
+
+ }
+
+ public void encodeItemsContainerBegin(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.DIV_ELEM, component);
+ responseWriter.writeAttribute(HTML.ID_ATTRIBUTE, getContainerElementId(
+ facesContext, component), null);
+ //responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul", null);
+ }
+
+ public void encodeItemsContainerEnd(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.endElement(HTML.DIV_ELEM);
+ }
+
+ public void encodeItem(FacesContext facesContext,
+ AbstractAutoComplete comboBox, Object item) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.DIV_ELEM, comboBox);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE,
+ "cb_option cb_font rf-ac-i", null);
+
+ if (comboBox.getChildCount() > 0) {
+ for (UIComponent child : comboBox.getChildren()) {
+ child.encodeAll(facesContext);
+ }
+ } else {
+ if (item != null) {
+ // TODO nick - use converter
+ String value = null;
+ if (comboBox.getItemConverter() != null) {
+ value = comboBox.getItemConverter().getAsString(
+ facesContext, comboBox, item);
+ }
+ if (value != null) {
+ writer.writeText(value, null);
+ }
+ writer.writeText(item, null);
+ //writer.writeText(InputUtils.getConvertedValue(facesContext, comboBox, item), null);
+ }
+ }
+
+ writer.endElement(HTML.DIV_ELEM);
+
+ }
+
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,37 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.AbstractAutoComplete;
+
+public class AutocompleteGridLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
+ AutoCompleteEncodeStrategy {
+
+ public void encodeFakeItem(FacesContext facesContext, UIComponent component)
+ throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void encodeItemsContainerBegin(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void encodeItemsContainerEnd(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void encodeItem(FacesContext facesContext,
+ AbstractAutoComplete comboBox, Object nextItem) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,65 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.AbstractAutoComplete;
+
+public class AutocompleteListLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
+ AutoCompleteEncodeStrategy {
+
+ public void encodeFakeItem(FacesContext facesContext, UIComponent component)
+ throws IOException {
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.LI_ELEMENT, component);
+ responseWriter.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none", null);
+ responseWriter.endElement(HTML.LI_ELEMENT);
+
+ }
+
+ public void encodeItemsContainerBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.UL_ELEMENT, component);
+ responseWriter.writeAttribute(HTML.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
+ responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul", null);
+ }
+
+ public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.endElement(HTML.UL_ELEMENT);
+ }
+
+ public void encodeItem(FacesContext facesContext,
+ AbstractAutoComplete comboBox, Object item) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.LI_ELEMENT, comboBox);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_option cb_font rf-ac-i", null);
+
+ if (comboBox.getChildCount() > 0) {
+ for (UIComponent child: comboBox.getChildren()) {
+ child.encodeAll(facesContext);
+ }
+ } else {
+ if (item != null) {
+ //TODO nick - use converter
+ String value = null;
+ if (comboBox.getItemConverter() != null) {
+ value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
+ }
+ if (value != null) {
+ writer.writeText(value, null);
+ }
+ writer.writeText(item, null);
+ }
+ }
+
+ writer.endElement(HTML.LI_ELEMENT);
+
+ }
+
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,37 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.AbstractAutoComplete;
+
+public class AutocompleteTableLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
+ AutoCompleteEncodeStrategy {
+
+ public void encodeFakeItem(FacesContext facesContext, UIComponent component)
+ throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void encodeItemsContainerBegin(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void encodeItemsContainerEnd(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void encodeItem(FacesContext facesContext,
+ AbstractAutoComplete comboBox, Object nextItem) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Deleted: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/ComboBoxRendererBase.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -1,236 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- */
-package org.richfaces.renderkit;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.el.ELException;
-import javax.el.MethodExpression;
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.PartialResponseWriter;
-import javax.faces.context.PartialViewContext;
-import javax.faces.context.ResponseWriter;
-
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractComboBox;
-import org.richfaces.component.MetaComponentResolver;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterators;
-
-/**
- * @author Nick Belaevski
- *
- */
- at ResourceDependencies({
- @ResourceDependency(library = "javax.faces", name = "jsf.js"),
- @ResourceDependency(name = "jquery.js"),
- @ResourceDependency(name = "jquery.position.js"),
- @ResourceDependency(name = "richfaces.js"),
- @ResourceDependency(name = "richfaces-event.js"),
- @ResourceDependency(name = "richfaces-base-component.js"),
- @ResourceDependency(name = "richfaces-selection.js"),
- @ResourceDependency(library = "org.richfaces", name = "AutoCompleteBase.js"),
- @ResourceDependency(library = "org.richfaces", name = "AutoComplete.js"),
- @ResourceDependency(library = "org.richfaces", name = "AutoComplete.ecss")
-
-})
-public abstract class ComboBoxRendererBase extends InputRendererBase implements MetaComponentRenderer {
-
- //TODO nick - handle parameter
- private Iterator<Object> getItems(FacesContext facesContext, AbstractComboBox component) {
- Object itemsObject = null;
-
- MethodExpression autocompleteMethod = component.getAutocompleteMethod();
- if (autocompleteMethod != null) {
- try {
- //String value = getInputValue(facesContext, component);
- Map<String, String> requestParameters = facesContext.getExternalContext().getRequestParameterMap();
- String value = requestParameters.get(component.getClientId(facesContext) + "Value");
- itemsObject = autocompleteMethod.invoke(facesContext.getELContext(),
- new Object[] {facesContext, component, value});
- } catch (ELException e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- } else {
- itemsObject = component.getAutocompleteList();
- }
-
- Iterator<Object> result;
-
- //TODO nick - primitive arrays support
- if (itemsObject instanceof Object[]) {
- result = Iterators.forArray((Object[]) itemsObject);
- } else if (itemsObject != null) {
- result = ((Iterable<Object>) itemsObject).iterator();
- } else {
- result = Iterators.emptyIterator();
- }
-
- return result;
- }
-
- private Object saveVar(FacesContext context, String var) {
- if (var != null) {
- Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
- return requestMap.get(var);
- }
-
- return null;
- }
-
- private void setVar(FacesContext context, String var, Object varObject) {
- if (var != null) {
- Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
- requestMap.put(var, varObject);
- }
- }
-
- protected void encodeItemContainerBegin(FacesContext facesContext, AbstractComboBox comboBox, Object item) throws IOException {
- ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.LI_ELEMENT, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_option cb_font rf-ac-i", null);
- }
-
- protected void encodeItemContainerEnd(FacesContext facesContext, AbstractComboBox comboBox, Object item) throws IOException {
- ResponseWriter writer = facesContext.getResponseWriter();
- writer.endElement(HTML.LI_ELEMENT);
- }
-
- protected void encodeItem(FacesContext facesContext, AbstractComboBox comboBox, Object item) throws IOException {
- ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.LI_ELEMENT, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_option cb_font rf-ac-i", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child: comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- //TODO nick - use converter
- writer.writeText(item, null);
- }
- }
-
- writer.endElement(HTML.LI_ELEMENT);
- }
-
- protected void encodeFakeItem(FacesContext context, UIComponent component) throws IOException {
- ResponseWriter responseWriter = context.getResponseWriter();
- responseWriter.startElement(HTML.LI_ELEMENT, component);
- responseWriter.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none", null);
- responseWriter.endElement(HTML.LI_ELEMENT);
- }
-
- protected void encodeItems(FacesContext facesContext, UIComponent component, List<Object> fetchValues) throws IOException {
- AbstractComboBox comboBox = (AbstractComboBox) component;
-
- encodeItemsContainerBegin(facesContext, component);
-
- boolean hasEncodedElements = false;
-
- Object savedVar = saveVar(facesContext, comboBox.getVar());
-
- for (Iterator<Object> items = getItems(facesContext, comboBox); items.hasNext(); ) {
- hasEncodedElements = true;
-
- Object nextItem = items.next();
- setVar(facesContext, comboBox.getVar(), nextItem);
-
- encodeItem(facesContext, comboBox, nextItem);
- fetchValues.add(comboBox.getFetchValue());
- }
-
- setVar(facesContext, comboBox.getVar(), savedVar);
-
- if (!hasEncodedElements) {
- //TODO nick - ?
- }
-
- encodeItemsContainerEnd(facesContext, component);
- }
-
- protected String getContainerElementId(FacesContext facesContext, UIComponent component) {
- return component.getClientId(facesContext) + "Items";
- }
-
- protected void encodeItemsContainerBegin(FacesContext facesContext, UIComponent component) throws IOException {
- ResponseWriter responseWriter = facesContext.getResponseWriter();
- responseWriter.startElement(HTML.UL_ELEMENT, component);
- responseWriter.writeAttribute(HTML.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
- responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul", null);
- }
-
- protected void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
- ResponseWriter responseWriter = facesContext.getResponseWriter();
- responseWriter.endElement(HTML.UL_ELEMENT);
- }
-
- protected void encodeItemsContainer(FacesContext facesContext, UIComponent component) throws IOException {
- encodeItemsContainerBegin(facesContext, component);
- encodeFakeItem(facesContext, component);
- encodeItemsContainerEnd(facesContext, component);
- }
-
- @Override
- protected void doDecode(FacesContext context, UIComponent component) {
- super.doDecode(context, component);
-
- Map<String, String> requestParameters = context.getExternalContext().getRequestParameterMap();
- if (requestParameters.get(component.getClientId(context) + ".ajax") != null) {
- PartialViewContext pvc = context.getPartialViewContext();
- pvc.getRenderIds().add(component.getClientId(context) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + AbstractComboBox.ITEMS_META_COMPONENT_ID);
- }
- }
-
- public void encodeMetaComponent(FacesContext context, UIComponent component, String metaComponentId)
- throws IOException {
- if (AbstractComboBox.ITEMS_META_COMPONENT_ID.equals(metaComponentId)) {
-
- List<Object> fetchValues = new ArrayList<Object>();
-
- PartialResponseWriter partialWriter = context.getPartialViewContext().getPartialResponseWriter();
- partialWriter.startUpdate(getContainerElementId(context, component));
- encodeItems(context, component, fetchValues);
- partialWriter.endUpdate();
-
- if (!fetchValues.isEmpty() && Iterators.find(fetchValues.iterator(), Predicates.notNull()) != null) {
- Map<String, Object> dataMap = AjaxContext.getCurrentInstance(context).getResponseComponentDataMap();
- dataMap.put(component.getClientId(context), fetchValues);
- }
- } else {
- throw new IllegalArgumentException(metaComponentId);
- }
- }
-}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteBaseGradient.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteBaseGradient.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteBaseGradient.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.renderkit.html.images;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.richfaces.resource.CacheableResource;
+import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.ImageType;
+import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.StateHolderResource;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+ at DynamicResource
+public abstract class AutoCompleteBaseGradient implements Java2DUserResource, CacheableResource, StateHolderResource {
+
+ private static final Dimension DIMENSION = new Dimension(18, 8);
+
+ private String topColorSkinParameter;
+
+ private String bottomColorSkinParameter;
+
+ private Color topColor;
+
+ private Color bottomColor;
+
+ public Map<String, String> getResponseHeaders() {
+ return null;
+ }
+
+ public Date getLastModified() {
+ return null;
+ }
+
+ public ImageType getImageType() {
+ return ImageType.PNG;
+ }
+
+ public Dimension getDimension() {
+ return DIMENSION;
+ }
+
+ public void paint(Graphics2D graphics2d, Dimension dimension) {
+ GradientPaint paint = new GradientPaint(0, 0, topColor, 0, dimension.height, bottomColor);
+ graphics2d.setPaint(paint);
+ graphics2d.fill(new Rectangle(dimension));
+ }
+
+ public boolean isCacheable(FacesContext context) {
+ return true;
+ }
+
+ public Date getExpires(FacesContext context) {
+ return null;
+ }
+
+ public int getTimeToLive(FacesContext context) {
+ return 0;
+ }
+
+ public String getEntityTag(FacesContext context) {
+ return null;
+ }
+
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {
+ Skin skin = SkinFactory.getInstance().getSkin(context);
+
+ Integer topColor = skin.getColorParameter(context, topColorSkinParameter);
+ Integer bottomColor = skin.getColorParameter(context, bottomColorSkinParameter);
+
+ dataOutput.writeInt(topColor);
+ dataOutput.writeInt(bottomColor);
+ }
+
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {
+ topColor = new Color(dataInput.readInt());
+ bottomColor = new Color(dataInput.readInt());
+ }
+
+ public boolean isTransient() {
+ return false;
+ }
+
+ protected void setTopColorSkinParameter(String topColorSkinParameter) {
+ this.topColorSkinParameter = topColorSkinParameter;
+ }
+
+ protected void setBottomColorSkinParameter(String bottomColorSkinParameter) {
+ this.bottomColorSkinParameter = bottomColorSkinParameter;
+ }
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteButtonGradient.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteButtonGradient.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteButtonGradient.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.renderkit.html.images;
+
+import org.richfaces.resource.DynamicResource;
+import org.richfaces.skin.Skin;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+ at DynamicResource
+public class AutoCompleteButtonGradient extends AutoCompleteBaseGradient {
+
+ public AutoCompleteButtonGradient() {
+ setTopColorSkinParameter(Skin.HEADER_GRADIENT_COLOR);
+ setBottomColorSkinParameter(Skin.HEADER_BACKGROUND_COLOR);
+ }
+
+}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteFieldGradient.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteFieldGradient.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/AutoCompleteFieldGradient.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.renderkit.html.images;
+
+import org.richfaces.resource.DynamicResource;
+import org.richfaces.skin.Skin;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+ at DynamicResource
+public class AutoCompleteFieldGradient extends AutoCompleteBaseGradient {
+
+ public AutoCompleteFieldGradient() {
+ setTopColorSkinParameter(Skin.ADDITIONAL_BACKGROUND_COLOR);
+ setBottomColorSkinParameter(Skin.CONTROL_BACKGROUND_COLOR);
+ }
+}
Deleted: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxBaseGradient.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxBaseGradient.java 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxBaseGradient.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -1,126 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- */
-package org.richfaces.renderkit.html.images;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.GradientPaint;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-
-import org.richfaces.resource.CacheableResource;
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.resource.ImageType;
-import org.richfaces.resource.Java2DUserResource;
-import org.richfaces.resource.StateHolderResource;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-
-/**
- * @author Nick Belaevski
- *
- */
- at DynamicResource
-public abstract class ComboBoxBaseGradient implements Java2DUserResource, CacheableResource, StateHolderResource {
-
- private static final Dimension DIMENSION = new Dimension(18, 8);
-
- private String topColorSkinParameter;
-
- private String bottomColorSkinParameter;
-
- private Color topColor;
-
- private Color bottomColor;
-
- public Map<String, String> getResponseHeaders() {
- return null;
- }
-
- public Date getLastModified() {
- return null;
- }
-
- public ImageType getImageType() {
- return ImageType.PNG;
- }
-
- public Dimension getDimension() {
- return DIMENSION;
- }
-
- public void paint(Graphics2D graphics2d, Dimension dimension) {
- GradientPaint paint = new GradientPaint(0, 0, topColor, 0, dimension.height, bottomColor);
- graphics2d.setPaint(paint);
- graphics2d.fill(new Rectangle(dimension));
- }
-
- public boolean isCacheable(FacesContext context) {
- return true;
- }
-
- public Date getExpires(FacesContext context) {
- return null;
- }
-
- public int getTimeToLive(FacesContext context) {
- return 0;
- }
-
- public String getEntityTag(FacesContext context) {
- return null;
- }
-
- public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {
- Skin skin = SkinFactory.getInstance().getSkin(context);
-
- Integer topColor = skin.getColorParameter(context, topColorSkinParameter);
- Integer bottomColor = skin.getColorParameter(context, bottomColorSkinParameter);
-
- dataOutput.writeInt(topColor);
- dataOutput.writeInt(bottomColor);
- }
-
- public void readState(FacesContext context, DataInput dataInput) throws IOException {
- topColor = new Color(dataInput.readInt());
- bottomColor = new Color(dataInput.readInt());
- }
-
- public boolean isTransient() {
- return false;
- }
-
- protected void setTopColorSkinParameter(String topColorSkinParameter) {
- this.topColorSkinParameter = topColorSkinParameter;
- }
-
- protected void setBottomColorSkinParameter(String bottomColorSkinParameter) {
- this.bottomColorSkinParameter = bottomColorSkinParameter;
- }
-}
Deleted: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxButtonGradient.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxButtonGradient.java 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxButtonGradient.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -1,39 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- */
-package org.richfaces.renderkit.html.images;
-
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.skin.Skin;
-
-/**
- * @author Nick Belaevski
- *
- */
- at DynamicResource
-public class ComboBoxButtonGradient extends ComboBoxBaseGradient {
-
- public ComboBoxButtonGradient() {
- setTopColorSkinParameter(Skin.HEADER_GRADIENT_COLOR);
- setBottomColorSkinParameter(Skin.HEADER_BACKGROUND_COLOR);
- }
-
-}
Deleted: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxFieldGradient.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxFieldGradient.java 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/renderkit/html/images/ComboBoxFieldGradient.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- */
-package org.richfaces.renderkit.html.images;
-
-import org.richfaces.resource.DynamicResource;
-import org.richfaces.skin.Skin;
-
-/**
- * @author Nick Belaevski
- *
- */
- at DynamicResource
-public class ComboBoxFieldGradient extends ComboBoxBaseGradient {
-
- public ComboBoxFieldGradient() {
- setTopColorSkinParameter(Skin.ADDITIONAL_BACKGROUND_COLOR);
- setBottomColorSkinParameter(Skin.CONTROL_BACKGROUND_COLOR);
- }
-}
Added: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/AutoCompleteHandler.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/AutoCompleteHandler.java (rev 0)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/AutoCompleteHandler.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.view.facelets;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.DateTimeConverter;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+import org.richfaces.MethodMetadata;
+import org.richfaces.component.AbstractAutoComplete;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+//TODO nick - this should be generated by CDK
+public class AutoCompleteHandler extends ComponentHandler {
+
+ private static final MetaRule AUTOCOMPLETE_METHOD_META_RULE = new MetaRule() {
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
+ if (meta.isTargetInstanceOf(AbstractAutoComplete.class)) {
+ if ("autocompleteMethod".equals(name)) {
+ return new MethodMetadata(attribute, FacesContext.class, UIComponent.class, String.class) {
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractAutoComplete) instance).setAutocompleteMethod(getMethodExpression(ctx));
+ }
+ };
+ }
+ /*if ("converter".equals(name)) {
+ return new ConverterMetadata(attribute) {
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractComboBox) instance).setConverter((Converter) this.getAttr()
+ .getObject(ctx, Converter.class));
+ }
+ };
+ }*/
+ /*if ("itemConverter".equals(name)) {
+ return new ConverterMetadata(attribute) {
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractComboBox) instance).setItemConverter((Converter) this.getAttr()
+ .getObject(ctx, Converter.class));
+ }
+ };
+ }*/
+ }
+
+ return null;
+ }
+ };
+
+ public AutoCompleteHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(AUTOCOMPLETE_METHOD_META_RULE);
+ return metaRuleset;
+ }
+ static abstract class ConverterMetadata extends Metadata {
+
+ private final TagAttribute attr;
+
+ public ConverterMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ public TagAttribute getAttr() {
+ return attr;
+ }
+
+ }
+}
Deleted: sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/java/org/richfaces/view/facelets/ComboBoxHandler.java 2010-08-13 17:34:18 UTC (rev 18631)
@@ -1,74 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- */
-package org.richfaces.view.facelets;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.view.facelets.ComponentConfig;
-import javax.faces.view.facelets.ComponentHandler;
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.MetaRule;
-import javax.faces.view.facelets.MetaRuleset;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.MetadataTarget;
-import javax.faces.view.facelets.TagAttribute;
-
-import org.richfaces.MethodMetadata;
-import org.richfaces.component.AbstractComboBox;
-
-/**
- * @author Nick Belaevski
- *
- */
-//TODO nick - this should be generated by CDK
-public class ComboBoxHandler extends ComponentHandler {
-
- private static final MetaRule AUTOCOMPLETE_METHOD_META_RULE = new MetaRule() {
-
- @Override
- public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
- if (meta.isTargetInstanceOf(AbstractComboBox.class)) {
- if ("autocompleteMethod".equals(name)) {
- return new MethodMetadata(attribute, FacesContext.class, UIComponent.class, String.class) {
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((AbstractComboBox) instance).setAutocompleteMethod(getMethodExpression(ctx));
- }
- };
- }
- }
-
- return null;
- }
- };
-
- public ComboBoxHandler(ComponentConfig config) {
- super(config);
- }
-
- @Override
- protected MetaRuleset createMetaRuleset(Class type) {
- MetaRuleset metaRuleset = super.createMetaRuleset(type);
- metaRuleset.addRule(AUTOCOMPLETE_METHOD_META_RULE);
- return metaRuleset;
- }
-
-}
Modified: sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.ecss 2010-08-13 17:34:18 UTC (rev 18631)
@@ -29,14 +29,14 @@
border-style: solid;
border-color: '#{richSkin.panelBorderColor}';
display: inline-block;
- background-image: "url(#{resource['org.richfaces.renderkit.html.images.ComboBoxFieldGradient']})";
+ background-image: "url(#{resource['org.richfaces.renderkit.html.images.AutoCompleteFieldGradient']})";
background-repeat: repeat-x;
background-position: top left;
background-color: '#{richSkin.controlBackgroundColor}';
}
.cb_button {
- background-image: "url(#{resource['org.richfaces.renderkit.html.images.ComboBoxButtonGradient']})";
+ background-image: "url(#{resource['org.richfaces.renderkit.html.images.AutoCompleteButtonGradient']})";
background-repeat: repeat-x;
background-position: top left;
background-color: '#{richSkin.headerBackgroundColor}';
Modified: sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-08-13 17:34:18 UTC (rev 18631)
@@ -191,7 +191,7 @@
}
}
- var ajaxError = function () {
+ var ajaxError = function (event) {
//alert("error");
}
@@ -199,7 +199,6 @@
//caution: JSF submits inputs with empty names causing "WARNING: Parameters: Invalid chunk ignored." in Tomcat log
var params = {};
params[this.id + ".ajax"] = "1";
-
rf.ajax(this.id, event, {parameters: params, error: ajaxError, complete:ajaxSuccess});
};
@@ -237,6 +236,9 @@
};
var onChangeValue = function (event, value) {
+ //if(this.options.onchange){
+ //this.options.onchange.call(this, event);
+ //}
selectItem.call(this);
// value is undefined if called from AutoCompleteBase onChange
@@ -249,20 +251,28 @@
this.options.ajaxMode && callAjax.call(this, event, subValue);
return;
}
-
+ if(!this.cache){
+ return;
+ }
var newItems = this.cache.getItems(subValue);
this.items = $(newItems);
//TODO: works only with simple markup, not with <tr>
$(rf.getDomElement(this.id+ID.ITEMS)).empty().append(newItems);
this.index = -1;
this.value = subValue;
+ if (subValue.length<this.options.minChars){
+ this.hide();
+ }
if (this.options.selectFirst) {
if (event.which == rf.KEYS.RETURN || event.type == "click") {
this.setInputValue(subValue);
+ return;
} else {
selectItem.call(this, 0, false, event.which == rf.KEYS.BACKSPACE || event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT);
+ return;
}
}
+ this.setInputValue(subValue);
};
var getSelectedItemValue = function () {
@@ -329,10 +339,10 @@
/*
* Protected methods
*/
- __updateState: function () {
+ __updateState: function (event) {
var subValue = this.__getSubValue();
// called from onShow method, not actually value changed
- if (this.items.length==0 && subValue.length>=this.options.minChars && this.isFirstAjax) {
+ if (this.items.length==0 && this.isFirstAjax) {
this.options.ajaxMode && callAjax.call(this, event, subValue);
}
return;
@@ -370,9 +380,11 @@
//rf.getDomElement(this.fieldId).focus();
},
__onShow: function (event) {
- if (event.which != rf.KEYS.BACKSPACE && this.items && this.items.length>0) {
- if (this.index!=0 && this.options.selectFirst) {
- selectItem.call(this, 0);
+ if (event.which != rf.KEYS.BACKSPACE) {
+ if(this.items && this.items.length>0){
+ if (this.index!=0 && this.options.selectFirst) {
+ selectItem.call(this, 0);
+ }
}
}
},
Modified: sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-08-13 17:34:18 UTC (rev 18631)
@@ -65,7 +65,7 @@
var inputEventHandlers = {};
- if (this.options.buttonId) {
+ if (this.options.buttonId && !this.options.disabled) {
inputEventHandlers["mousedown"+this.namespace] = onButtonShow;
inputEventHandlers["mouseup"+this.namespace] = onSelectMouseUp;
rf.Event.bindById(this.options.buttonId, inputEventHandlers, this);
@@ -133,7 +133,10 @@
}
if (flag) {
this.currentValue = this.getInputValue();
- onShow.call(this, event);
+ if(value && value.length>=this.options.minChars){
+ onShow.call(this, event);
+ }
+
}
}
};
@@ -196,7 +199,7 @@
/*
* public API functions definition
*/
- var show = function (event) {
+ var show = function (event, showButtonPressed) {
if (!this.isVisible) {
if (this.__onBeforeShow(event)!=false) {
this.scrollElements = rf.Event.bindScrollEventHandlers(this.selectId, this.hide, this, this.namespace);
@@ -207,7 +210,7 @@
}
$(rf.getDomElement(this.selectId)).setPosition({id: this.fieldId}, {type:"DROPDOWN", offset:[0,20]}).show();
this.isVisible = true;
- this.__onShow(event);
+ this.__onShow(event, showButtonPressed);
}
}
};
Modified: sandbox/trunk/ui/inputs/combobox/src/main/templates/comboBox.template.xml
===================================================================
--- sandbox/trunk/ui/inputs/combobox/src/main/templates/comboBox.template.xml 2010-08-13 16:34:09 UTC (rev 18630)
+++ sandbox/trunk/ui/inputs/combobox/src/main/templates/comboBox.template.xml 2010-08-13 17:34:18 UTC (rev 18631)
@@ -5,25 +5,58 @@
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
<cc:interface>
- <cdk:class>org.richfaces.renderkit.html.ComboBoxRenderer</cdk:class>
- <cdk:superclass>org.richfaces.renderkit.ComboBoxRendererBase</cdk:superclass>
+ <cdk:class>org.richfaces.renderkit.html.AutoCompleteRenderer</cdk:class>
+ <cdk:superclass>org.richfaces.renderkit.AutoCompleteRendererBase</cdk:superclass>
<cdk:component-family>javax.faces.Input</cdk:component-family>
- <cdk:renderer-type>org.richfaces.ComboBoxRenderer
+ <cdk:renderer-type>org.richfaces.AutoCompleteRenderer
</cdk:renderer-type>
<cdk:renders-children>true</cdk:renders-children>
</cc:interface>
<cc:implementation>
+ <cdk:object type="java.lang.Object" name="disabled" value="#{component.attributes['disabled']}" />
<div id="#{clientId}" class="cb_field_width cb_field">
<input id="#{clientId}Value" name="#{clientId}Value" type="hidden" class="cb_font cb_input" />
<div style="position : relative; overflow : hidden; text-align : left; padding-right : 21px;">
- <input id="#{clientId}Input" name="#{clientId}" type="text" class="cb_font cb_input" />
+ <input onclick="#{component.attributes['onclick']}"
+ ondblclick="#{component.attributes['ondblclick']}"
+ 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']}"
+ onkeydown="#{component.attributes['onkeydown']}"
+ onkeypress="#{component.attributes['onkeypress']}" id="#{clientId}Input" disabled="#{disabled}" name="#{clientId}" type="text" class="cb_font cb_input" />
+ <c:if test="#{component.attributes['showButton']}">
+ <c:if test="#{component.attributes['disabled']}">
<div id="#{clientId}Button" class="cb_button">
<div class="cb_button_arrow"></div>
</div>
+ </c:if>
+ <c:if test="#{!component.attributes['disabled']}">
+ <div id="#{clientId}Button" class="cb_button">
+ <div class="cb_button_arrow"></div>
+ </div>
+ </c:if>
+ </c:if>
</div>
- <div id="#{clientId}List" class="cb_list_cord">
+ <div onclick="#{component.attributes['onlistclick']}"
+ ondblclick="#{component.attributes['onlistdblclick']}"
+ onmouseup="#{component.attributes['onlistmouseup']}"
+ onmousedown="#{component.attributes['onlistmousedown']}"
+ 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']}"
+ id="#{clientId}List" class="cb_list_cord">
<div class="cb_shadow">
<div class="cb_shadow_t"></div>
@@ -42,8 +75,8 @@
</div>
<script type="text/javascript">
new RichFaces.ui.AutoComplete("#{clientId}",
- "#{clientId}Input", {buttonId:"#{clientId}Button",
- selectedItemClass:'cb_select'});
+ "#{clientId}Input", #{getScriptOptions(component)}
+ );
</script>
</div>
</cc:implementation>
More information about the richfaces-svn-commits
mailing list