You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/11/25 04:53:35 UTC

svn commit: r1038906 - in /myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter: ConvertDateTimeTagHandler.java _DateTimeConverterRule.java

Author: lu4242
Date: Thu Nov 25 03:53:35 2010
New Revision: 1038906

URL: http://svn.apache.org/viewvc?rev=1038906&view=rev
Log:
MFCOMMONS-25 Add Facelets Support to myfaces commons

Added:
    myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_DateTimeConverterRule.java
Modified:
    myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertDateTimeTagHandler.java

Modified: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertDateTimeTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertDateTimeTagHandler.java?rev=1038906&r1=1038905&r2=1038906&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertDateTimeTagHandler.java (original)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertDateTimeTagHandler.java Thu Nov 25 03:53:35 2010
@@ -22,9 +22,10 @@ import com.sun.facelets.FaceletContext;
 import com.sun.facelets.tag.MetaRuleset;
 import com.sun.facelets.tag.TagAttribute;
 import com.sun.facelets.tag.TagAttributeException;
+import com.sun.facelets.tag.jsf.ConvertHandler;
 import com.sun.facelets.tag.jsf.ConverterConfig;
 
-public class ConvertDateTimeTagHandler extends ConverterBaseTagHandler
+public class ConvertDateTimeTagHandler extends ConvertHandler
 {
 
     public ConvertDateTimeTagHandler(ConverterConfig config)
@@ -42,6 +43,8 @@ public class ConvertDateTimeTagHandler e
     {
         MetaRuleset ruleSet = super.createMetaRuleset(type);
         
+        ruleSet.addRule(_DateTimeConverterRule.Instance);
+        
         //Add locale rule
         ruleSet.addRule(_LocaleRule.Instance);
         

Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_DateTimeConverterRule.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_DateTimeConverterRule.java?rev=1038906&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_DateTimeConverterRule.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/_DateTimeConverterRule.java Thu Nov 25 03:53:35 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.converter;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+
+final class _DateTimeConverterRule extends MetaRule {
+
+    final static class ValueBindingMetadata extends Metadata {
+
+        private final String name;
+
+        private final TagAttribute attr;
+
+        private final Class type;
+
+        public ValueBindingMetadata(String name, Class type, TagAttribute attr) {
+            this.name = name;
+            this.attr = attr;
+            this.type = type;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((DateTimeConverter) instance).setValueBinding(this.name,
+                    new LegacyValueBinding(this.attr.getValueExpression(ctx,
+                            this.type)));
+        }
+
+    }
+
+    public final static _DateTimeConverterRule Instance = new _DateTimeConverterRule();
+
+    public _DateTimeConverterRule() {
+        super();
+    }
+
+    public Metadata applyRule(String name, TagAttribute attribute,
+            MetadataTarget meta) {
+        if (meta.isTargetInstanceOf(DateTimeConverter.class)) {
+
+            // if component and dynamic, then must set expression
+            if (!attribute.isLiteral()) {
+                Class type = meta.getPropertyType(name);
+                if (type == null) {
+                    type = Object.class;
+                }
+                return new ValueBindingMetadata(name, type, attribute);
+            }
+        }
+        return null;
+    }
+}