You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/04/27 15:34:00 UTC

svn commit: r768973 - in /incubator/click/trunk/click/extras/src/org/apache/click/extras/control: FieldColumn.java FormTable.java

Author: sabob
Date: Mon Apr 27 13:33:59 2009
New Revision: 768973

URL: http://svn.apache.org/viewvc?rev=768973&view=rev
Log:
added new method FieldColumn.setProperty. CLK-528

Modified:
    incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FieldColumn.java
    incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FieldColumn.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FieldColumn.java?rev=768973&r1=768972&r2=768973&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FieldColumn.java (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FieldColumn.java Mon Apr 27 13:33:59 2009
@@ -18,6 +18,9 @@
  */
 package org.apache.click.extras.control;
 
+import java.util.HashMap;
+import java.util.Map;
+import ognl.Ognl;
 import org.apache.click.Context;
 import org.apache.click.control.Column;
 import org.apache.click.control.Field;
@@ -64,6 +67,9 @@
     /** The columns field to process and render. */
     protected Field field;
 
+    /** The ognl context map. */
+    private transient Map ognlContext;
+
     // ----------------------------------------------------------- Constructors
 
     /**
@@ -145,6 +151,51 @@
         this.field = field;
     }
 
+    /**
+     * Set a row value based on the given property name and value. The given row
+     * can either be a Java Object or a Map instance.
+     * <p/>
+     * If the row is a Java Object this method uses OGNL to set the value of the
+     * row based on the property name. Property names can be specified using a
+     * path expression e.g: "person.address.city".
+     * <p/>
+     * If the row object is a <tt>Map</tt> this method will attempt to set the
+     * map's key/value pair based on the property name and value. The key
+     * of the map is matched against the property name. If a key matches the
+     * property name, the value will be copied to the map.
+     * <p/>
+     * <b>Note:</b> you can access the underlying Field using {@link #getField()}.
+     *
+     * @param row the row object to obtain the property from
+     * @param propertyName the name of the property
+     * @param the row object property value
+     *
+     * @return the named row object property value
+     * @throws RuntimeException if an error occurred obtaining the property
+     */
+    public void setProperty(Object row, String propertyName, Object value) {
+        if (row instanceof Map) {
+            Map map = (Map) row;
+            if (map.containsKey(propertyName)) {
+                map.put(propertyName, value);
+            }
+        } else {
+            if (ognlContext == null) {
+                ognlContext = new HashMap();
+            }
+
+            try {
+                Ognl.setValue(propertyName,
+                              ognlContext,
+                              row,
+                              value);
+
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
     // ------------------------------------------------------ Protected Methods
 
     /**
@@ -177,6 +228,7 @@
             Form form = formTable.getForm();
 
             if (formTable.getRenderSubmittedValues()
+                && !formTable.getControlLink().isClicked()
                 && form.isFormSubmission()) {
 
                 field.onProcess();

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java?rev=768973&r1=768972&r2=768973&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java Mon Apr 27 13:33:59 2009
@@ -469,22 +469,16 @@
                     Column column = (Column) columnList.get(j);
 
                     if (column instanceof FieldColumn) {
-                        Field field = ((FieldColumn) column).getField();
+                        FieldColumn fieldColumn = (FieldColumn) column;
+                        Field field = fieldColumn.getField();
 
                         field.setName(column.getName() + "_" + i);
 
                         field.onProcess();
 
                         if (field.isValid()) {
-                            try {
-                                Ognl.setValue(column.getName(),
-                                              ognlContext,
-                                              row,
-                                              field.getValueObject());
-
-                            } catch (Exception e) {
-                                throw new RuntimeException(e);
-                            }
+                            fieldColumn.setProperty(row, column.getName(),
+                                field.getValueObject());
                         } else {
                             getForm().setError(getMessage("formtable-error"));
                         }