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/13 17:41:55 UTC

svn commit: r1034802 - in /myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter: ConvertEnumTagHandler.java EnumConverter.java

Author: lu4242
Date: Sat Nov 13 16:41:55 2010
New Revision: 1034802

URL: http://svn.apache.org/viewvc?rev=1034802&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/ConvertEnumTagHandler.java
Modified:
    myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/EnumConverter.java

Added: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertEnumTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertEnumTagHandler.java?rev=1034802&view=auto
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertEnumTagHandler.java (added)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/ConvertEnumTagHandler.java Sat Nov 13 16:41:55 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.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 ConvertEnumTagHandler extends ConvertHandler
+{
+    private final TagAttribute targetClass;
+    
+    public ConvertEnumTagHandler(ConverterConfig config)
+    {
+        super(config);
+        this.targetClass = this.getAttribute("targetClass");
+    }
+
+    public void setAttributes(FaceletContext ctx, Object obj)
+    {
+        super.setAttributes(ctx, obj);
+        EnumConverter c = (EnumConverter) obj;
+        if (this.targetClass != null)
+        {
+            if (this.targetClass.isLiteral())
+            {
+                try
+                {
+                    c.setTargetClass(org.apache.myfaces.commons.util.ClassUtils.classForName(this.targetClass.getValue()));
+                }
+                catch (ClassNotFoundException e)
+                {
+                    throw new TagAttributeException(this.targetClass,"Cannot find class assigned: "+this.targetClass.getValue(),e);
+                }
+            }
+            else
+            {
+                c.setTargetClass((Class) this.targetClass.getObject(ctx, Class.class));
+            }
+        }
+    }
+
+    @Override
+    protected MetaRuleset createMetaRuleset(Class type)
+    {
+        return super.createMetaRuleset(type).ignore("targetClass");
+    }
+}

Modified: myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/EnumConverter.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/EnumConverter.java?rev=1034802&r1=1034801&r2=1034802&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/EnumConverter.java (original)
+++ myfaces/commons/branches/jsf_11/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/EnumConverter.java Sat Nov 13 16:41:55 2010
@@ -39,7 +39,8 @@ import javax.faces.application.FacesMess
  */
 @JSFConverter(
    name = "mcc:convertEnum",
-   tagClass = "org.apache.myfaces.commons.converter.ConvertEnumTag")
+   tagClass = "org.apache.myfaces.commons.converter.ConvertEnumTag",
+   tagHandler = "org.apache.myfaces.commons.converter.ConvertEnumTagHandler")
 public class EnumConverter implements Converter, StateHolder {
     
     public static final String CONVERTER_ID = "org.apache.myfaces.commons.converter.Enum";