[richfaces-svn-commits] JBoss Rich Faces SVN: r18953 - in trunk/ui/input/ui/src/main: java/org/richfaces/view/facelets and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Aug 24 13:09:32 EDT 2010


Author: amarkhel
Date: 2010-08-24 13:09:31 -0400 (Tue, 24 Aug 2010)
New Revision: 18953

Modified:
   trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
   trunk/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java
   trunk/ui/input/ui/src/main/templates/autocomplete.template.xml
Log:
Fix checkstyle and add support for mode attribbute

Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java	2010-08-24 15:57:13 UTC (rev 18952)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java	2010-08-24 17:09:31 UTC (rev 18953)
@@ -88,6 +88,11 @@
         utils.addToScriptHash(options, "onerror", attributes.get("onerror"));
         utils.addToScriptHash(options, "onbeforedomupdate", attributes.get("onbeforedomupdate"));
         utils.addToScriptHash(options, "onchange", attributes.get("onchange"));
+        if (attributes.get("mode").equals("ajax")){
+            utils.addToScriptHash(options, "isCachedAjax", false, "true");
+        } else if (attributes.get("mode").equals("client")) {
+            utils.addToScriptHash(options, "ajaxMode", false, "true");
+        }
         StringBuilder builder = new StringBuilder();
         builder.append(ScriptUtils.toScript(options));
         return builder.toString();
@@ -201,23 +206,28 @@
     protected void encodeItemsContainer(FacesContext facesContext, UIComponent component) throws IOException {
         AutocompleteEncodeStrategy strategy = getStrategy(component);
         strategy.encodeItemsContainerBegin(facesContext, component);
-        strategy.encodeFakeItem(facesContext, component);
+        if (component.getAttributes().get("mode").equals("client")) {
+            List<Object> fetchValues = new ArrayList<Object>();
+            this.encodeItems(facesContext, component, fetchValues);
+        } else {
+            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)) {
+            if (comboBox.getLayout().equals(AutocompleteLayout.div.toString())) {
                 return new AutocompleteDivLayoutStrategy();
             }
-            if (comboBox.getLayout().equals(AutocompleteLayout.grid)) {
+            if (comboBox.getLayout().equals(AutocompleteLayout.grid.toString())) {
                 return new AutocompleteGridLayoutStrategy();
             }
-            if (comboBox.getLayout().equals(AutocompleteLayout.list)) {
+            if (comboBox.getLayout().equals(AutocompleteLayout.list.toString())) {
                 return new AutocompleteListLayoutStrategy();
             }
-            if (comboBox.getLayout().equals(AutocompleteLayout.table)) {
+            if (comboBox.getLayout().equals(AutocompleteLayout.table.toString())) {
                 return new AutocompleteTableLayoutStrategy();
             }
         }
@@ -226,12 +236,21 @@
 
     @Override
     protected void doDecode(FacesContext context, UIComponent component) {
-        if (InputUtils.isDisabled(component)) {
+        AbstractAutocomplete autocomplete = (AbstractAutocomplete)component;
+    	if (InputUtils.isDisabled(autocomplete)) {
             return;
         }
+        Map<String, String> requestParameters = context.getExternalContext().getRequestParameterMap();
+        Object value = requestParameters.get(component.getClientId(context) + "Value");
+        if (value != null) {
+            if(autocomplete.getConverter() != null){
+                value = autocomplete.getConverter().getAsObject(context, component, value.toString());
+            }
+            autocomplete.setSubmittedValue(value);
+        }
         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(

Modified: trunk/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java	2010-08-24 15:57:13 UTC (rev 18952)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java	2010-08-24 17:09:31 UTC (rev 18953)
@@ -21,8 +21,10 @@
  */
 package org.richfaces.view.facelets;
 
+import javax.el.ValueExpression;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
 import javax.faces.view.facelets.ComponentConfig;
 import javax.faces.view.facelets.ComponentHandler;
 import javax.faces.view.facelets.FaceletContext;
@@ -39,31 +41,44 @@
  * @author Nick Belaevski
  * 
  */
-// TODO nick - this should be generated by CDK
+//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) {
+        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) {
+                    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)); } }; }
-                 */
+
+                if ("converter".equals(name)) {
+                    return new ConverterMetadata(attribute) {
+                        public void applyMetadata(FaceletContext ctx, Object instance) {
+                            ((AbstractAutocomplete) instance).setConverter(this.getConverter(ctx,
+                                            (AbstractAutocomplete) instance,
+                                            this.getAttr().getValueExpression(ctx, Converter.class)));
+                        }
+                    };
+                }
+
+                if ("itemConverter".equals(name)) {
+                    return new ConverterMetadata(attribute) {
+                        public void applyMetadata(FaceletContext ctx, Object instance) {
+                            ((AbstractAutocomplete) instance).setItemConverter(this.getConverter(ctx,
+                                    (AbstractAutocomplete) instance,
+                                    this.getAttr().getValueExpression(ctx, Converter.class)));
+                        }
+                    };
+                }
+
             }
 
             return null;
@@ -71,7 +86,7 @@
     };
 
     public AutocompleteHandler(ComponentConfig config) {
-        super(config);
+		super(config);
     }
 
     @Override
@@ -93,5 +108,38 @@
             return attr;
         }
 
+        public Converter getConverter(FaceletContext ctx,
+                AbstractAutocomplete component, ValueExpression converter) {
+            ValueExpression ve = null;
+            Converter c = null;
+            if (converter != null) {
+                ve = converter;
+                try {
+                    c = (Converter) ve.getValue(ctx);
+                } catch (Exception e) {
+					// ok
+                }
+
+            }
+            if (c == null) {
+                c = this.createConverter(ctx, component);
+            }
+            if (c == null) {
+				// throw new TagException(this.getTag(), "No Converter was
+				// created");
+            }
+            return c;
+        }
+
+        private String getConverterId(FaceletContext ctx) {
+            return this.getAttr().getValue(ctx);
+        }
+
+        private Converter createConverter(FaceletContext ctx,
+			    AbstractAutocomplete component) {
+            return ctx.getFacesContext().getApplication().createConverter(
+				    getConverterId(ctx));
+        }
+
     }
 }

Modified: trunk/ui/input/ui/src/main/templates/autocomplete.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/autocomplete.template.xml	2010-08-24 15:57:13 UTC (rev 18952)
+++ trunk/ui/input/ui/src/main/templates/autocomplete.template.xml	2010-08-24 17:09:31 UTC (rev 18953)
@@ -29,7 +29,7 @@
 				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="rf-au-font rf-au-input" />
+				onkeypress="#{component.attributes['onkeypress']}" id="#{clientId}Input" value="#{component.attributes['value']}"  disabled="#{disabled}" name="#{clientId}" type="text" class="rf-au-font rf-au-input" />
                 <c:if test="#{component.attributes['showButton']}">
                 <c:if test="#{component.attributes['disabled']}">
                 <div id="#{clientId}Button" class="rf-au-button">



More information about the richfaces-svn-commits mailing list