You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2009/05/15 13:24:35 UTC

svn commit: r775087 - /myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/jsf/component/DynaConfig.java

Author: skitching
Date: Fri May 15 11:24:35 2009
New Revision: 775087

URL: http://svn.apache.org/viewvc?rev=775087&view=rev
Log:
Allow an od:dynaFormConfig tag to specify a ComponentHandler name. The ability to set a ComponentHandler already exists via the
@ComponentHandler java annotation; this allows it to also be set via a tag.

Modified:
    myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/jsf/component/DynaConfig.java

Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/jsf/component/DynaConfig.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/jsf/component/DynaConfig.java?rev=775087&r1=775086&r2=775087&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/jsf/component/DynaConfig.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/jsf/component/DynaConfig.java Fri May 15 11:24:35 2009
@@ -18,7 +18,9 @@
  */
 package org.apache.myfaces.orchestra.dynaForm.jsf.component;
 
+import org.apache.myfaces.orchestra.dynaForm.jsf.guiBuilder.DynaFormComponentHandler;
 import org.apache.myfaces.orchestra.dynaForm.metadata.MetaFieldWritable;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIComponentBase;
@@ -48,6 +50,7 @@
     private Boolean displayOnly;
     private Boolean readOnly;
     private Boolean disabled;
+    private String componentHandler;
 
     @Override
     public String getFamily()
@@ -140,6 +143,28 @@
     }
 
     /**
+     * @see #setComponentHandler.
+     */
+    public String getComponentHandler()
+    {
+        if (componentHandler != null)
+        {
+            return componentHandler;
+        }
+        ValueBinding vb = getValueBinding("componentHandler");
+        return vb != null ? (String) vb.getValue(getFacesContext()) : null;
+    }
+
+    /**
+     * Render this field by using the managed bean with the specified name,
+     * which must be a subtype of DynaFormComponentHandler.
+     */
+    public void setComponentHandler(String beanName)
+    {
+        this.componentHandler = beanName;
+    }
+
+    /**
      * @see #setFor(String)
      */
     public String getFor()
@@ -170,6 +195,7 @@
         displayOnly = (Boolean) states[3];
         readOnly = (Boolean) states[4];
         disabled = (Boolean) states[5];
+        componentHandler = (String) states[6];
     }
 
     @Override
@@ -182,7 +208,8 @@
                 forProperty,
                 displayOnly,
                 readOnly,
-                disabled
+                disabled,
+                componentHandler
             };
     }
 
@@ -205,6 +232,25 @@
             field.setDisabled(getDisabled().booleanValue());
         }
 
+        String ch = getComponentHandler();
+        if (ch != null)
+        {
+            Object componentHandlerBean = FrameworkAdapter.getCurrentInstance().getBean(ch);
+            if (componentHandlerBean == null)
+            {
+                throw new IllegalArgumentException(
+                    "no component handler with bean name " + ch + " found.");
+            }
+            if (!(componentHandlerBean instanceof DynaFormComponentHandler))
+            {
+                throw new IllegalArgumentException(
+                    "component handler with bean name " + ch + 
+                    " doesn't implement the " + DynaFormComponentHandler.class.getName() + " interface.");
+            }
+
+            field.setComponentHandler((DynaFormComponentHandler) componentHandlerBean);
+       }
+
         if (getChildCount() > 0)
         {
             field.setWantedComponent((UIComponent) getChildren().get(0));