click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r923191 - in /click/trunk/click/extras/src/org/apache/click/extras/cayenne: PropertySelect.java QuerySelect.java
Date Mon, 15 Mar 2010 12:19:16 GMT
Author: sabob
Date: Mon Mar 15 12:19:15 2010
New Revision: 923191

URL: http://svn.apache.org/viewvc?rev=923191&view=rev
Log:
removed bindRequestValue dependency on optionList values and general cleanup

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/cayenne/PropertySelect.java
    click/trunk/click/extras/src/org/apache/click/extras/cayenne/QuerySelect.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/cayenne/PropertySelect.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/cayenne/PropertySelect.java?rev=923191&r1=923190&r2=923191&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/cayenne/PropertySelect.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/cayenne/PropertySelect.java Mon Mar
15 12:19:15 2010
@@ -118,8 +118,7 @@ import org.apache.commons.lang.StringUti
  * public void onDestroy() {
  *     customerSelect.getOptionList().clear();
  *     super.onDestroy();
- * }
- * </pre>
+ * } </pre>
  *
  * @see CayenneForm
  * @see QuerySelect
@@ -128,7 +127,7 @@ public class PropertySelect extends Sele
 
     private static final long serialVersionUID = 1L;
 
-    // ----------------------------------------------------- Instance Variables
+    // Instance Variables -----------------------------------------------------
 
     /** The option label rendering decorator. */
     protected Decorator decorator;
@@ -163,7 +162,7 @@ public class PropertySelect extends Sele
     /** The property value object. */
     protected DataObject valueObject;
 
-    // ----------------------------------------------------------- Constructors
+    // Constructors -----------------------------------------------------------
 
     /**
      * Create a PropertySelect field with the given name.
@@ -220,7 +219,7 @@ public class PropertySelect extends Sele
         super();
     }
 
-    // ------------------------------------------------------------- Properties
+    // Properties -------------------------------------------------------------
 
     /**
      * Return the option label rendering decorator.
@@ -267,6 +266,7 @@ public class PropertySelect extends Sele
      *
      * @return false
      */
+    @Override
     public boolean isMultiple() {
         return false;
     }
@@ -278,6 +278,7 @@ public class PropertySelect extends Sele
      *
      * @param value the multiple options can be selected flag
      */
+    @Override
     public void setMultiple(boolean value) {
         String msg = "PropertySelect does not support multiple property values";
         throw new UnsupportedOperationException(msg);
@@ -390,6 +391,7 @@ public class PropertySelect extends Sele
      *
      * @return the property <tt>DataObject</tt> value
      */
+    @Override
     public Object getValueObject() {
         return valueObject;
     }
@@ -402,13 +404,14 @@ public class PropertySelect extends Sele
      *
      * @param object the object value to set
      */
+    @Override
     public void setValueObject(Object object) {
         if (object != null) {
             DataObject dataObject = (DataObject) object;
             valueObject = dataObject;
 
-            CayenneForm form = (CayenneForm) getForm();
-            String pkName = CayenneUtils.getPkName(form.getDataContext(),
+            CayenneForm cayenneForm = (CayenneForm) getForm();
+            String pkName = CayenneUtils.getPkName(cayenneForm.getDataContext(),
                                                    dataObject.getClass());
 
             Object pk = dataObject.getObjectId().getIdSnapshot().get(pkName);
@@ -419,50 +422,44 @@ public class PropertySelect extends Sele
         }
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
-     * Bind the request value to the control, looking up the <tt>DataObject</tt>
-     * based on the submitted primary key value and setting this object as
-     * the Select <tt>valueObject</tt>.
+     * Process the page request returning true to continue processing or false
+     * otherwise.
+     * <p/>
+     * This method delegates to {@link #loadDataObject()} to load the
+     * <tt>DataObject</tt>.
      *
-     * @see Select#bindRequestValue()
+     * @see org.apache.click.control.Select#onProcess()
      */
-    public void bindRequestValue() {
-
-        loadOptionList();
-
-        super.bindRequestValue();
-
-        CayenneForm form = (CayenneForm) getForm();
-        Class doClass = form.getDataObjectClass();
-
-        if (StringUtils.isNotBlank(getValue())) {
-
-            String getterName = ClickUtils.toGetterName(getName());
-
-            try {
-                Method method = doClass.getMethod(getterName);
-
-                DataContext dataContext = form.getDataContext();
-
-                Class propertyClass = method.getReturnType();
-
-                String propertyPk = getValue();
-
-                valueObject = CayenneUtils.getObjectForPK(dataContext,
-                                                          propertyClass,
-                                                          propertyPk);
+    @Override
+    public boolean onProcess() {
+        boolean continueProcessing = super.onProcess();
+        loadDataObject();
+        return continueProcessing;
+    }
 
-                setValue(propertyPk.toString());
+    /**
+     * Clear the cached valueObject.
+     *
+     * @see org.apache.click.Control#onDestroy()
+     */
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        valueObject = null;
+    }
 
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
+    /**
+     * Validate the QuerySelect request submission.
+     */
+    @Override
+    public void validate() {
+        // Ensure the option list is loaded before validation
+        loadOptionList();
 
-        } else {
-            valueObject = null;
-        }
+        super.validate();
     }
 
     /**
@@ -475,16 +472,17 @@ public class PropertySelect extends Sele
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         loadOptionList();
 
         // Select option value if value defined and not form submission
         if (getValueObject() == null && !getForm().isFormSubmission()) {
 
-            CayenneForm form = (CayenneForm) getForm();
-            DataContext dataContext = form.getDataContext();
-            Class doClass = form.getDataObjectClass();
-            Object doPk = form.getDataObjectPk();
+            CayenneForm cayenneForm = (CayenneForm) getForm();
+            DataContext dataContext = cayenneForm.getDataContext();
+            Class doClass = cayenneForm.getDataObjectClass();
+            Object doPk = cayenneForm.getDataObjectPk();
 
             if (doPk != null) {
                 DataObject dataObject =
@@ -511,17 +509,43 @@ public class PropertySelect extends Sele
         super.render(buffer);
     }
 
+    // Protected Methods ------------------------------------------------------
+
     /**
-     * Clear the cached valueObject.
-     *
-     * @see org.apache.click.Control#onDestroy()
+     * Load the <tt>DataObject</tt> based on the submitted primary key value
and
+     * setting this object as the Select <tt>valueObject</tt>.
      */
-    public void onDestroy() {
-        super.onDestroy();
-        valueObject = null;
-    }
+    protected void loadDataObject() {
+        CayenneForm cayenneForm = (CayenneForm) getForm();
+        Class doClass = cayenneForm.getDataObjectClass();
+
+        if (StringUtils.isNotBlank(getValue())) {
+
+            String getterName = ClickUtils.toGetterName(getName());
+
+            try {
+                Method method = doClass.getMethod(getterName);
+
+                DataContext dataContext = cayenneForm.getDataContext();
 
-    // ------------------------------------------------------ Protected Methods
+                Class propertyClass = method.getReturnType();
+
+                String propertyPk = getValue();
+
+                valueObject = CayenneUtils.getObjectForPK(dataContext,
+                                                          propertyClass,
+                                                          propertyPk);
+
+                setValue(propertyPk.toString());
+
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+
+        } else {
+            valueObject = null;
+        }
+    }
 
     /**
      * Load the Select options list. This method will attempt to select the
@@ -550,8 +574,8 @@ public class PropertySelect extends Sele
             return;
         }
 
-        CayenneForm form = (CayenneForm) getForm();
-        DataContext dataContext = form.getDataContext();
+        CayenneForm cayenneForm = (CayenneForm) getForm();
+        DataContext dataContext = cayenneForm.getDataContext();
 
         try {
             List list = null;
@@ -580,7 +604,7 @@ public class PropertySelect extends Sele
                  list = dataContext.performQuery(getQueryName(), false);
 
             } else {
-                Class doClass = form.getDataObjectClass();
+                Class doClass = cayenneForm.getDataObjectClass();
                 String getterName = ClickUtils.toGetterName(getName());
                 Method method = doClass.getMethod(getterName);
                 Class propertyClass = method.getReturnType();

Modified: click/trunk/click/extras/src/org/apache/click/extras/cayenne/QuerySelect.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/cayenne/QuerySelect.java?rev=923191&r1=923190&r2=923191&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/cayenne/QuerySelect.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/cayenne/QuerySelect.java Mon Mar
15 12:19:15 2010
@@ -135,7 +135,7 @@ public class QuerySelect extends Select 
     /** The option list Cayenne <tt>SelectQuery</tt>. */
     protected SelectQuery selectQuery;
 
-    // ----------------------------------------------------------- Constructors
+    // Constructors -----------------------------------------------------------
 
     /**
      * Create a QuerySelect field with the given name.
@@ -192,7 +192,7 @@ public class QuerySelect extends Select 
         super();
     }
 
-    // ------------------------------------------------------------- Properties
+    // Properties -------------------------------------------------------------
 
     /**
      * Return the option label rendering decorator.
@@ -367,18 +367,17 @@ public class QuerySelect extends Select 
         this.selectQuery = selectQuery;
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
-     * Bind the request value to the control.
-     *
-     * @see Select#bindRequestValue()
+     * Validate the QuerySelect request submission.
      */
-    public void bindRequestValue() {
-
+    @Override
+    public void validate() {
+        // Ensure the option list is loaded before validation
         loadOptionList();
 
-        super.bindRequestValue();
+        super.validate();
     }
 
     /**
@@ -391,12 +390,13 @@ public class QuerySelect extends Select 
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         loadOptionList();
         super.render(buffer);
     }
 
-    // ------------------------------------------------------ Protected Methods
+    // Protected Methods ------------------------------------------------------
 
     /**
      * Load the Select options list.



Mime
View raw message