You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2007/03/07 01:12:04 UTC

svn commit: r515387 - in /tapestry/tapestry4/trunk: tapestry-annotations/src/java/org/apache/tapestry/form/ tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/localization/ tapestry-framework/src/java/org/apache/tapestry/coerce/ tapestr...

Author: jkuhnert
Date: Tue Mar  6 16:12:03 2007
New Revision: 515387

URL: http://svn.apache.org/viewvc?view=rev&rev=515387
Log:
Refactored PropertySelection component a little:
-) Moved rendering of individual options into a new delegate IOptionRenderer (with a default impl bound to the new optionRenderer 
parameter that does the same thing as the existing render)
-) Added IOptionSelectionModel.isDisabled(int index) to allow for the possibility of rendering the full range of html attributes / 
things that can go into a select list.
-) Added unit tests / etc..

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/DefaultOptionRenderer.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IOptionRenderer.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestPropertySelection.java
Modified:
    tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/localization/LocaleModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/coerce/StringConvertedPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/NullWriter.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.jwc
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/SelectPropertySelectionRenderer.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/StringPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/DefaultAttribute.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/MarkupWriterImpl.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
    tapestry/tapestry4/trunk/tapestry-portlet/src/test/org/apache/tapestry/portlet/TestApplicationPortlet.java

Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java Tue Mar  6 16:12:03 2007
@@ -74,6 +74,11 @@
         return _set[index - 1].toString();
     }
     
+    public boolean isDisabled(int index)
+    {
+        return false;
+    }
+    
     /**
      * {@inheritDoc}
      */

Modified: tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/localization/LocaleModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/localization/LocaleModel.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/localization/LocaleModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/localization/LocaleModel.java Tue Mar  6 16:12:03 2007
@@ -69,6 +69,11 @@
         return Integer.toString(index);
     }
 
+    public boolean isDisabled(int index)
+    {
+        return false;
+    }
+    
     public Object translateValue(String value)
     {
         int index = Integer.parseInt(value);

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/coerce/StringConvertedPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/coerce/StringConvertedPropertySelectionModel.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/coerce/StringConvertedPropertySelectionModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/coerce/StringConvertedPropertySelectionModel.java Tue Mar  6 16:12:03 2007
@@ -97,6 +97,11 @@
         return getEntry(index)._value;
     }
 
+    public boolean isDisabled(int index)
+    {
+        return false;
+    }
+    
     public Object translateValue(String value)
     {
         // Values are the same on the client and the server, so no translation needed.

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/NullWriter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/NullWriter.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/NullWriter.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/NullWriter.java Tue Mar  6 16:12:03 2007
@@ -143,6 +143,10 @@
     {
     }
     
+    public void attribute(String value)
+    {
+    }
+    
     public void appendAttribute(String name, boolean value)
     {
     }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java Tue Mar  6 16:12:03 2007
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -21,18 +21,15 @@
 
 import org.apache.commons.beanutils.BeanUtils;
 
-
 /**
- * This class is a property selection model for an object list.
- * This is used in PropertySelection, MultiplePropertySelection or Palette tapestry components.
- *
- * For example, to use for a Hospital class, and have the labels be the hospital names.
- * <code>
+ * This class is a property selection model for an object list. This is used in PropertySelection,
+ * MultiplePropertySelection or Palette tapestry components. For example, to use for a Hospital
+ * class, and have the labels be the hospital names. <code>
  * List&lt;Hospital&gt; list = ...;
  * return new BeanPropertySelectionModel(hospitals, "name");
  * </code>
  * This will use getName() on the Hospital object, as its display.
- *
+ * 
  * @author Gabriel Handford
  */
 public class BeanPropertySelectionModel implements IPropertySelectionModel, Serializable
@@ -46,74 +43,105 @@
     /**
      * Build an empty property selection model.
      */
-    public BeanPropertySelectionModel() {
+    public BeanPropertySelectionModel()
+    {
         this(Arrays.asList(new Object[0]), null);
     }
-    
+
     /**
      * Build a bean property selection model.
-     * @param list The list
-     * @param labelField The label field
+     * 
+     * @param list
+     *            The list
+     * @param labelField
+     *            The label field
      */
-    public BeanPropertySelectionModel(List list, String labelField) {
+    public BeanPropertySelectionModel(List list, String labelField)
+    {
         _list = list;
         _labelField = labelField;
     }
-    
+
     /**
      * Build a bean property selection model.
-     * @param c Collection
-     * @param labelField The label field
+     * 
+     * @param c
+     *            Collection
+     * @param labelField
+     *            The label field
      */
-    public BeanPropertySelectionModel(Collection c, String labelField) {
+    public BeanPropertySelectionModel(Collection c, String labelField)
+    {
         _list = new ArrayList(c);
         _labelField = labelField;
     }
-    
+
     /**
      * Get the number of options.
+     * 
      * @return option count
      */
-    public int getOptionCount() { return _list.size(); }
-    
+    public int getOptionCount()
+    {
+        return _list.size();
+    }
+
     /**
      * Get the option at index.
-     * @param index Index
+     * 
+     * @param index
+     *            Index
      * @return object Object at index
      */
-    public Object getOption(int index) {
+    public Object getOption(int index)
+    {
         return _list.get(index);
     }
 
     /**
      * Get the label at index.
-     * @param index Index
+     * 
+     * @param index
+     *            Index
      * @return label Label at index
      */
-    public String getLabel(int index) {
+    public String getLabel(int index)
+    {
         Object obj = _list.get(index);
         try {
+
             return BeanUtils.getProperty(obj, _labelField);
         } catch (Exception e) {
             throw new RuntimeException("Error getting property", e);
         }
     }
-    
+
     /**
      * Get the value at index.
-     * @param index Index
+     * 
+     * @param index
+     *            Index
      * @return value Value at index
      */
-    public String getValue(int index) {
+    public String getValue(int index)
+    {
         return String.valueOf(index);
     }
 
+    public boolean isDisabled(int index)
+    {
+        return false;
+    }
+    
     /**
      * Translate value to object.
-     * @param value Value
+     * 
+     * @param value
+     *            Value
      * @return object Object from value
      */
-    public Object translateValue(String value) {
+    public Object translateValue(String value)
+    {
         return getOption(Integer.parseInt(value));
     }
 }

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/DefaultOptionRenderer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/DefaultOptionRenderer.java?view=auto&rev=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/DefaultOptionRenderer.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/DefaultOptionRenderer.java Tue Mar  6 16:12:03 2007
@@ -0,0 +1,84 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.form;
+
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRequestCycle;
+
+
+/**
+ * The default implementation of {@link IOptionRenderer} which is used by 
+ * the {@link PropertySelection} component if no other renderer is specified
+ * in the component parameters.
+ */
+public class DefaultOptionRenderer implements IOptionRenderer
+{
+
+    /**
+     * Default instance used by {@link PropertySelection} if no custom renderer is 
+     * specified.
+     */
+    
+    public static final IOptionRenderer DEFAULT_INSTANCE = new DefaultOptionRenderer();
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void renderOptions(IMarkupWriter writer, IRequestCycle cycle, IPropertySelectionModel model, Object selected)
+    {
+        int count = model.getOptionCount();
+        boolean foundSelected = false;
+        
+        for (int i = 0; i < count; i++)
+        {
+            Object option = model.getOption(i);
+            
+            writer.begin("option");
+            writer.attribute("value", model.getValue(i));
+
+            if (!foundSelected && isEqual(option, selected))
+            {
+                writer.attribute("selected", "selected");
+                
+                foundSelected = true;
+            }
+            
+            if (model.isDisabled(i))
+                writer.attribute("disabled", "true");
+            
+            writer.print(model.getLabel(i));
+
+            writer.end();
+
+            writer.println();
+        }
+    }
+    
+    protected boolean isEqual(Object left, Object right)
+    {
+        // Both null, or same object, then are equal
+
+        if (left == right)
+            return true;
+        
+        // If one is null, the other isn't, then not equal.
+        
+        if (left == null || right == null)
+            return false;
+        
+        // Both non-null; use standard comparison.
+        
+        return left.equals(right);
+    }
+}

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IOptionRenderer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IOptionRenderer.java?view=auto&rev=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IOptionRenderer.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IOptionRenderer.java Tue Mar  6 16:12:03 2007
@@ -0,0 +1,41 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.form;
+
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRequestCycle;
+
+
+/**
+ * Interface used by {@link PropertySelection} to render each option.
+ */
+public interface IOptionRenderer
+{
+
+    /**
+     * Called after the initial <code>&lt;select&gt;</code> tag has been rendered. It is expected that implementations
+     * will then do whatever is necessary to render each option available in the model and defer writing the end 
+     * <code>&lt;/select&gt;</code> to the calling component.
+     * 
+     * @param writer
+     *          The markup writer to use.
+     * @param cycle
+     *          The associated cycle.
+     * @param model
+     *          Model containing values / labels / etc..
+     * @param selected
+     *          The currently selected object value, if any. Will be null if no value is currently selected.
+     */
+    void renderOptions(IMarkupWriter writer, IRequestCycle cycle, IPropertySelectionModel model, Object selected);
+}

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IPropertySelectionModel.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IPropertySelectionModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/IPropertySelectionModel.java Tue Mar  6 16:12:03 2007
@@ -65,6 +65,15 @@
     String getValue(int index);
 
     /**
+     * Used to help rendering of options that should be marked with the html <code>disabled</code>
+     * attribute.
+     * 
+     * @param index The option to check.
+     * @return True if the option shouldn't be selectable, false otherwise.
+     */
+    boolean isDisabled(int index);
+    
+    /**
      * Returns the option corresponding to a value. This is used when interpreting submitted form
      * parameters.
      */

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java Tue Mar  6 16:12:03 2007
@@ -60,6 +60,11 @@
             return null;
         }
 
+        public boolean isDisabled(int index)
+        {
+            return false;
+        }
+        
         /**
          * @see org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.lang.String)
          */
@@ -207,6 +212,11 @@
         return (index == 0) ? _value : _model.getValue(index - 1);
     }
 
+    public boolean isDisabled(int index)
+    {
+        return false;
+    }
+    
     /**
      * @see org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.lang.String)
      */

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.java Tue Mar  6 16:12:03 2007
@@ -44,8 +44,7 @@
  * @author Howard Lewis Ship
  * @author Paul Ferraro
  */
-public abstract class PropertySelection extends AbstractFormComponent 
-    implements ValidatableField
+public abstract class PropertySelection extends AbstractFormComponent implements ValidatableField
 {   
     /**
      * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
@@ -60,9 +59,6 @@
         if (isDisabled())
             writer.attribute("disabled", "disabled");
         
-        if (getSubmitOnChange())
-            writer.attribute("onchange", "javascript: this.form.events.submit();");
-        
         renderIdAttribute(writer, cycle);
         
         renderDelegateAttributes(writer, cycle);
@@ -79,31 +75,8 @@
         if (model == null)
             throw Tapestry.createRequiredParameterException(this, "model");
         
-        int count = model.getOptionCount();
-        boolean foundSelected = false;
-        Object value = getValue();
+        getOptionRenderer().renderOptions(writer, cycle, model, getValue());
         
-        for (int i = 0; i < count; i++)
-        {
-            Object option = model.getOption(i);
-
-            writer.begin("option");
-            writer.attribute("value", model.getValue(i));
-
-            if (!foundSelected && isEqual(option, value))
-            {
-                writer.attribute("selected", "selected");
-
-                foundSelected = true;
-            }
-
-            writer.print(model.getLabel(i));
-
-            writer.end();
-
-            writer.println();
-        }
-
         writer.end(); // <select>
 
         renderDelegateSuffix(writer, cycle);
@@ -130,33 +103,16 @@
         }
     }
     
-    private boolean isEqual(Object left, Object right)
-    {
-        // Both null, or same object, then are equal
-
-        if (left == right)
-            return true;
-        
-        // If one is null, the other isn't, then not equal.
-        
-        if (left == null || right == null)
-            return false;
-        
-        // Both non-null; use standard comparison.
-        
-        return left.equals(right);
-    }
-    
     public abstract IPropertySelectionModel getModel();
     
     /** @since 2.2 * */
-    public abstract boolean getSubmitOnChange();
-
-    /** @since 2.2 * */
     public abstract Object getValue();
 
     /** @since 2.2 * */
     public abstract void setValue(Object value);
+    
+    /** Responsible for rendering individual options. */
+    public abstract IOptionRenderer getOptionRenderer();
     
     /**
      * Injected.

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.jwc?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.jwc (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/PropertySelection.jwc Tue Mar  6 16:12:03 2007
@@ -30,22 +30,17 @@
   <parameter name="value" required="yes"/>
   
   <parameter name="model" required="yes"/>
-  	
+  
   <parameter name="disabled"/>
-    
-  <parameter name="submitOnChange" deprecated="true">
-  	<description>
-  	Enables logic to submit containing form when value changes.
-  	</description>
-  </parameter>
   
   <parameter name="displayName"/>
-  <parameter name="validators"/>
   
-  <parameter name="id" property="idParameter" default-value="id"/>
-
+  <parameter name="validators" />
+  
+  <parameter name="optionRenderer" default-value="ognl:@org.apache.tapestry.form.DefaultOptionRenderer@DEFAULT_INSTANCE" cache="no" />
+  
   <reserved-parameter name="name"/>
-
+  
   <inject property="validatableFieldSupport" object="service:tapestry.form.ValidatableFieldSupport"/>
   
 </component-specification>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/SelectPropertySelectionRenderer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/SelectPropertySelectionRenderer.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/SelectPropertySelectionRenderer.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/SelectPropertySelectionRenderer.java Tue Mar  6 16:12:03 2007
@@ -24,8 +24,7 @@
  * @author Howard Lewis Ship
  */
 
-public class SelectPropertySelectionRenderer implements
-        IPropertySelectionRenderer
+public class SelectPropertySelectionRenderer implements IPropertySelectionRenderer
 {
 
     /**
@@ -35,13 +34,13 @@
      * Navigator 4 will ignore this).
      */
 
-    public void beginRender(PropertySelection component, IMarkupWriter writer,
-            IRequestCycle cycle)
+    public void beginRender(PropertySelection component, IMarkupWriter writer, IRequestCycle cycle)
     {
         writer.begin("select");
         writer.attribute("name", component.getName());
 
-        if (component.isDisabled()) writer.attribute("disabled", "disabled");
+        if (component.isDisabled()) 
+            writer.attribute("disabled", "disabled");
 
         writer.println();
     }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/StringPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/StringPropertySelectionModel.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/StringPropertySelectionModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/StringPropertySelectionModel.java Tue Mar  6 16:12:03 2007
@@ -30,14 +30,25 @@
 
     private String[] _options;
 
+    private boolean[] _disabled;
+    
     /**
      * Standard constructor. The options are retained (not copied).
      */
-
     public StringPropertySelectionModel(String[] options)
     {
         this._options = options;
     }
+    
+    /**
+     * Standard constructor. The options are retained (not copied).
+     */
+
+    public StringPropertySelectionModel(String[] options, boolean[] disabled)
+    {
+        this(options);
+        _disabled = disabled;
+    }
 
     public int getOptionCount()
     {
@@ -67,6 +78,11 @@
         return Integer.toString(index);
     }
 
+    public boolean isDisabled(int index)
+    {
+        return _disabled != null && _disabled[index];
+    }
+    
     public Object translateValue(String value)
     {
         if (value == null)

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/DefaultAttribute.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/DefaultAttribute.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/DefaultAttribute.java Tue Mar  6 16:12:03 2007
@@ -23,8 +23,8 @@
  */
 public class DefaultAttribute implements Attribute
 {
-    private String _value;
-    private boolean _raw;
+    protected String _value;
+    protected boolean _raw;
     
     public DefaultAttribute(String value, boolean raw)
     {
@@ -60,7 +60,7 @@
         writer.print(' ');
         writer.print(name);
         writer.print("=\"");
-        
+
         if (_raw && _value != null) {
             
             writer.write(_value);

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/MarkupWriterImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/MarkupWriterImpl.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/MarkupWriterImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/MarkupWriterImpl.java Tue Mar  6 16:12:03 2007
@@ -156,6 +156,7 @@
         
         if (attr == null) {
             attr = new DefaultAttribute(value, true);
+            
             _attrMap.put(name, attr);
             return;
         }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java Tue Mar  6 16:12:03 2007
@@ -122,6 +122,11 @@
                 return Integer.toString(index);
             }
 
+            public boolean isDisabled(int index)
+            {
+                return false;
+            }
+            
             public Object translateValue(String value)
             {
                 return getOption(Integer.parseInt(value));

Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestPropertySelection.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestPropertySelection.java?view=auto&rev=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestPropertySelection.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestPropertySelection.java Tue Mar  6 16:12:03 2007
@@ -0,0 +1,145 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.form;
+
+import static org.easymock.EasyMock.expect;
+
+import org.apache.tapestry.IForm;
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.valid.IValidationDelegate;
+import org.apache.tapestry.valid.ValidatorException;
+import org.testng.annotations.Test;
+
+/**
+ * Tests {@link PropertySelection}.
+ * 
+ */
+@Test(sequential = true)
+public class TestPropertySelection extends BaseFormComponentTestCase
+{
+
+    public void test_Rewind()
+    {
+        ValidatableFieldSupport vfs = newMock(ValidatableFieldSupport.class);
+
+        IPropertySelectionModel model = new StringPropertySelectionModel(new String[] { "One", "Two", "Three" });
+        
+        PropertySelection component = newInstance(PropertySelection.class, 
+                new Object[]  { 
+            "validatableFieldSupport", vfs,
+            "model", model
+        });
+        
+        IRequestCycle cycle = newCycle();
+        
+        IForm form = newMock(IForm.class);
+        
+        IMarkupWriter writer = newWriter();
+        
+        IValidationDelegate delegate = newDelegate();
+        
+        expect(cycle.renderStackPush(component)).andReturn(component);
+        
+        trainGetForm(cycle, form);
+        trainWasPrerendered(form, writer, component, false);
+        trainGetDelegate(form, delegate);
+
+        delegate.setFormComponent(component);
+
+        trainGetElementId(form, component, "barney");
+        trainIsRewinding(form, true);
+        
+        trainGetParameter(cycle, "barney", "1");
+        
+        try
+        {
+            vfs.validate(component, writer, cycle, model.translateValue("1"));
+        }
+        catch (ValidatorException e)
+        {
+            unreachable();
+        }
+        
+        expect(cycle.renderStackPop()).andReturn(component);
+        
+        replay();
+
+        component.render(writer, cycle);
+
+        verify();
+        
+        assertEquals(component.getValue(), "Two");
+    }
+    
+    public void test_Render()
+    {
+        ValidatableFieldSupport vfs = newMock(ValidatableFieldSupport.class);
+        
+        IRequestCycle cycle = newCycle();
+        IForm form = newMock(IForm.class);
+
+        IMarkupWriter writer = newBufferWriter();
+
+        MockDelegate delegate = new MockDelegate();
+
+        IPropertySelectionModel model = new StringPropertySelectionModel(new String[] { "One", "Two", "Three" }, 
+                new boolean[] {false, false, true});
+        
+        PropertySelection component = newInstance(PropertySelection.class, 
+                new Object[]  { 
+            "id", "hannah",
+            "validatableFieldSupport", vfs,
+            "model", model,
+            "value", "One",
+            "optionRenderer", DefaultOptionRenderer.DEFAULT_INSTANCE
+        });
+        
+        expect(cycle.renderStackPush(component)).andReturn(component);
+        
+        trainGetForm(cycle, form);
+        trainWasPrerendered(form, writer, component, false);
+        trainGetDelegate(form, delegate);
+        
+        delegate.setFormComponent(component);
+
+        trainGetElementId(form, component, "hannah");
+        trainIsRewinding(form, false);
+        trainIsRewinding(cycle, false);
+        
+        form.setFormFieldUpdating(true);
+        
+        delegate.setFormComponent(component);
+        
+        trainGetDelegate(form, delegate);
+        
+        vfs.renderContributions(component, writer, cycle);
+
+        trainGetDelegate(form, delegate);
+        
+        expect(cycle.renderStackPop()).andReturn(component);
+        
+        replay();
+
+        component.render(writer, cycle);
+
+        verify();
+
+        assertBuffer("<span class=\"prefix\"><select name=\"hannah\" id=\"hannah\" class=\"validation-delegate\">\n" + 
+                "<option value=\"0\" selected=\"selected\">One</option>\n" + 
+                "<option value=\"1\">Two</option>\n" + 
+                "<option value=\"2\" disabled=\"true\">Three</option>\n" + 
+                "</select></span>");
+    }
+}

Modified: tapestry/tapestry4/trunk/tapestry-portlet/src/test/org/apache/tapestry/portlet/TestApplicationPortlet.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-portlet/src/test/org/apache/tapestry/portlet/TestApplicationPortlet.java?view=diff&rev=515387&r1=515386&r2=515387
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-portlet/src/test/org/apache/tapestry/portlet/TestApplicationPortlet.java (original)
+++ tapestry/tapestry4/trunk/tapestry-portlet/src/test/org/apache/tapestry/portlet/TestApplicationPortlet.java Tue Mar  6 16:12:03 2007
@@ -34,7 +34,7 @@
  * @author Howard M. Lewis Ship
  * @since 4.0
  */
-@Test
+@Test(sequential = true)
 public class TestApplicationPortlet extends BaseComponentTestCase
 {
     public static class ApplicationPortletFixture extends ApplicationPortlet



Re: svn commit: r515387 - in /tapestry/tapestry4/trunk: tapestry-annotations/src/java/org/apache/tapestry/form/ tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/localization/ tapestry-framework/src/java/org/apache/tapestry/coerce/ tapestr...

Posted by andyhot <an...@di.uoa.gr>.
jkuhnert@apache.org wrote:
> Author: jkuhnert
> Date: Tue Mar  6 16:12:03 2007
> New Revision: 515387
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=515387
> Log:
> Refactored PropertySelection component a little:
> -) Moved rendering of individual options into a new delegate IOptionRenderer (with a default impl bound to the new optionRenderer 
> parameter that does the same thing as the existing render)
> -) Added IOptionSelectionModel.isDisabled(int index) to allow for the possibility of rendering the full range of html attributes / 
> things that can go into a select list.
>   

Nice!

> -) Added unit tests / etc..
>   


-- 
Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
Tapestry / Tacos developer
Open Source / J2EE Consulting 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org