[gatein-commits] gatein SVN: r3844 - epp/portal/branches/EPP_5_0_Branch/webui/core/src/main/java/org/exoplatform/webui/form.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Aug 17 13:54:10 EDT 2010


Author: mpodolin
Date: 2010-08-17 13:54:09 -0400 (Tue, 17 Aug 2010)
New Revision: 3844

Modified:
   epp/portal/branches/EPP_5_0_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormMultiValueInputSet.java
Log:
JBEPP-405: GTNPORTAL-1223 and GTNPORTAL-1225 ported to the branch

Modified: epp/portal/branches/EPP_5_0_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormMultiValueInputSet.java
===================================================================
--- epp/portal/branches/EPP_5_0_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormMultiValueInputSet.java	2010-08-17 16:05:11 UTC (rev 3843)
+++ epp/portal/branches/EPP_5_0_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormMultiValueInputSet.java	2010-08-17 17:54:09 UTC (rev 3844)
@@ -31,6 +31,7 @@
 import java.io.Writer;
 import java.lang.reflect.Constructor;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -56,6 +57,8 @@
    private Class<? extends UIFormInputBase> clazz_;
 
    private Constructor constructor_ = null;
+   
+   private Object[] constructorParams_;
 
    /**
     * Whether this field is enabled
@@ -83,6 +86,10 @@
       return List.class;
    }
 
+   /**
+    * 
+    * @param clazz
+    */
    public void setType(Class<? extends UIFormInputBase> clazz)
    {
       this.clazz_ = clazz;
@@ -91,6 +98,43 @@
          constructor_ = constructors[0];
    }
 
+   /**
+    * define a <code>Constructor</code> which's invoked
+    * 
+    * @param constructorParameterTypes list of parameter type which is defined in constructor
+    * @throws SecurityException
+    * @throws NoSuchMethodException
+    */
+   public void setConstructorParameterTypes(Class<?>... constructorParameterTypes) throws SecurityException, NoSuchMethodException
+   {
+      Constructor<?> constructor = this.clazz_.getConstructor(constructorParameterTypes);
+      if(constructor != null)
+      {
+         this.constructor_ = constructor;
+      }
+   }
+   
+   /**
+    * pass values to the <code>Constructor</code>
+    * You only set constructor parameter values after seted constructor by {@link #setConstructorParameterTypes(Class...)}
+    * @param values
+    * @throws SecurityException
+    * @throws NoSuchMethodException
+    */
+   public void setConstructorParameterValues(Object[] values) throws SecurityException, NoSuchMethodException
+   {
+      this.constructorParams_ = values;
+//      List<Class<?>> parameterTypes = new ArrayList<Class<?>>();
+//      
+//      for (Object clazz : values)
+//      {
+//         parameterTypes.add(clazz.getClass());
+//      }
+//      
+//      Class<?> [] arrParameterTypes = (Class[]) parameterTypes.toArray(new Class[parameterTypes.size()]);
+//      this.setConstructorParameterTypes(arrParameterTypes);
+   }
+   
    public Class<? extends UIFormInputBase> getUIFormInputBase()
    {
       return clazz_;
@@ -202,19 +246,35 @@
 	   
 	  if(constructor_  == null) return  null;
       Class[] classes = constructor_.getParameterTypes();
-      Object[] params = new Object[classes.length];
-      for (int i = 0; i < classes.length; i++)
-      {
-         if (classes[i].isPrimitive())
+      UIFormInputBase inputBase;      
+      String compName = getId() + String.valueOf(idx);
+      if (classes.length > 0) {
+         if (constructorParams_ == null)
          {
-            if (classes[i] == boolean.class)
-               params[i] = false;
-            else
-               params[i] = 0;
+            Object[] params = new Object[classes.length];
+            for (int i = 0; i < classes.length; i++)
+            {
+               if (classes[i].isPrimitive())
+               {
+                  if (classes[i] == boolean.class)
+                     params[i] = false;
+                  else
+                     params[i] = 0;
+               }
+            }
+            params[0] = compName;
+            inputBase = (UIFormInputBase) constructor_.newInstance(params);
          }
+         else
+         {
+            inputBase = (UIFormInputBase) constructor_.newInstance(constructorParams_);
+         }
+      } else {
+         inputBase = (UIFormInputBase)constructor_.newInstance();
       }
-      params[0] = getId() + String.valueOf(idx);
-      UIFormInputBase inputBase = (UIFormInputBase)constructor_.newInstance(params);
+      
+      inputBase.setName(compName);
+      inputBase.setId(compName);
       List<Validator> validators = this.getValidators();
       if (validators != null)
       {



More information about the gatein-commits mailing list