cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r370138 - in /cocoon: branches/BRANCH_2_1_X/ trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/ trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/flow/javascript/v2/ trunk/...
Date Wed, 18 Jan 2006 13:33:44 GMT
Author: jbq
Date: Wed Jan 18 05:33:35 2006
New Revision: 370138

URL: http://svn.apache.org/viewcvs?rev=370138&view=rev
Log:
Fix COCOON-1621: Allow to use a <fd:value-count> validation rule with <fd:multivaluefield>
Fixes samples at /samples/blocks/forms/v2/example, but anyway, v2 will be removed soon

Modified:
    cocoon/branches/BRANCH_2_1_X/status.xml
    cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java
    cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java
    cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
    cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=370138&r1=370137&r2=370138&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Wed Jan 18 05:33:35 2006
@@ -180,6 +180,9 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.9" date="TBD">
+    <action dev="JBQ" type="fix" fixes-bug="COCOON-1621" due-to="Marco Rolappe" due-to-email="m_rolappe@web.de">
+      Allow to use a &lt;fd:value-count> validation rule with &lt;fd:multivaluefield>
+    </action>
     <action dev="JBQ" type="fix" fixes-bug="COCOON-1731" due-to="Philippe Gassmann" due-to-email="phil@anyware-tech.com">
       Allow to extend JXPathBinding outside the org.apache.cocoon.forms.binding package
     </action>

Modified: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java?rev=370138&r1=370137&r2=370138&view=diff
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java
(original)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java
Wed Jan 18 05:33:35 2006
@@ -113,7 +113,7 @@
                 if (rule.supportsType(datatype.getTypeClass(), datatype.isArrayType())) {
                     datatype.addValidationRule(rule);
                 } else {
-                    throw new Exception("Validation rule \"" + validationElements[i].getLocalName()
+ "\" cannot be used with strings, error at " + DomHelper.getLocation(validationElements[i]));
+                    throw new Exception("Validation rule \"" + validationElements[i].getLocalName()
+ "\" cannot be used with type <" + (datatype.isArrayType() ? "array of " : "") + datatype.getTypeClass().getName()
+ ">, error at " + DomHelper.getLocation(validationElements[i]));
                 }
             }
         }

Modified: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java?rev=370138&r1=370137&r2=370138&view=diff
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java
(original)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java
Wed Jan 18 05:33:35 2006
@@ -360,39 +360,8 @@
             }
             // fall through
         }
-        if (delegate instanceof DataWidget) {
-            value = unwrap(value);
-            if (value != null) {
-                // Coerce values
-                Datatype datatype = ((DataWidget)delegate).getDatatype();
-                Class typeClass = datatype.getTypeClass();
-                if (typeClass == String.class) {
-                    value = Context.toString(value);
-                } else if (typeClass == boolean.class || 
-                           typeClass == Boolean.class) {
-                    value = Context.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE;
-                } else {
-                    if (value instanceof Double) {
-                        // make cform accept a JS Number
-                        if (typeClass == long.class || typeClass == Long.class) {
-                            value = new Long(((Number)value).longValue());
-                        } else if (typeClass == int.class || 
-                                   typeClass == Integer.class) {
-                            value = new Integer(((Number)value).intValue());
-                        } else if (typeClass == float.class || 
-                                   typeClass == Float.class) {
-                            value = new Float(((Number)value).floatValue());
-                        } else if (typeClass == short.class || 
-                                   typeClass == Short.class) {
-                            value = new Short(((Number)value).shortValue());
-                        } else if (typeClass == BigDecimal.class) {
-                            value = new BigDecimal(((Number)value).doubleValue());
-                        }
-                    } 
-                }
-            }
-            delegate.setValue(value);
-        } else if (delegate instanceof BooleanField) {
+
+        if (delegate instanceof BooleanField) {
             BooleanField field = (BooleanField)delegate;
             field.setValue(BooleanUtils.toBooleanObject(Context.toBoolean(value)));
         } else if (delegate instanceof Repeater) {
@@ -454,7 +423,42 @@
                 values = (Object[])value;
             }
             field.setValues(values);
-        } else {
+        }
+        else if (delegate instanceof DataWidget) {
+            value = unwrap(value);
+            if (value != null) {
+                // Coerce values
+                Datatype datatype = ((DataWidget)delegate).getDatatype();
+                Class typeClass = datatype.getTypeClass();
+                if (typeClass == String.class) {
+                    value = Context.toString(value);
+                } else if (typeClass == boolean.class || 
+                           typeClass == Boolean.class) {
+                    value = Context.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE;
+                } else {
+                    if (value instanceof Double) {
+                        // make cform accept a JS Number
+                        if (typeClass == long.class || typeClass == Long.class) {
+                            value = new Long(((Number)value).longValue());
+                        } else if (typeClass == int.class || 
+                                   typeClass == Integer.class) {
+                            value = new Integer(((Number)value).intValue());
+                        } else if (typeClass == float.class || 
+                                   typeClass == Float.class) {
+                            value = new Float(((Number)value).floatValue());
+                        } else if (typeClass == short.class || 
+                                   typeClass == Short.class) {
+                            value = new Short(((Number)value).shortValue());
+                        } else if (typeClass == BigDecimal.class) {
+                            value = new BigDecimal(((Number)value).doubleValue());
+                        }
+                    } 
+                }
+            }
+            delegate.setValue(value);
+        }
+        else
+        {
             delegate.setValue(value);
         }
     }

Modified: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java?rev=370138&r1=370137&r2=370138&view=diff
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
(original)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
Wed Jan 18 05:33:35 2006
@@ -35,8 +35,17 @@
  * @version $Id$
  */
 public abstract class AbstractDatatypeWidgetDefinitionBuilder extends AbstractWidgetDefinitionBuilder
{
-    
-    protected void setupDefinition(Element widgetElement, AbstractDatatypeWidgetDefinition
definition) throws Exception {
+
+    protected void setupDefinition(Element widgetElement,
+            AbstractDatatypeWidgetDefinition definition) throws Exception
+    {
+        setupDefinition(widgetElement, definition, false);
+    }
+
+    protected void setupDefinition(Element widgetElement,
+            AbstractDatatypeWidgetDefinition definition, boolean isArrayType)
+        throws Exception
+    {
         super.setupDefinition(widgetElement, definition);
         // parse "label", "hint", etc.
         setDisplayData(widgetElement, definition);
@@ -46,13 +55,13 @@
         while (iter.hasNext()) {
             definition.addValueChangedListener((ValueChangedListener)iter.next());
         }
-        
+
         //---- parse "datatype"
         Element datatypeElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS,
"datatype");
         if (datatypeElement != null) {
-        	Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
-        	
-        	// ---- parse "initial-value"
+            Datatype datatype = datatypeManager.createDatatype(datatypeElement, isArrayType);
+
+            // ---- parse "initial-value"
             Object initialValue = null;
             Element initialValueElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS,
"initial-value", false);
             if (initialValueElement != null) {
@@ -66,11 +75,11 @@
                 }
                 initialValue = result.getResult();
             }
-            
+
             definition.setDatatype(datatype, initialValue);
         }
-        
-        
+
+
         //---- parse "selection-list"
         // FIXME: pass the manager to the definition as a side effect. Should be removed
         // when definition are managed like components.
@@ -81,14 +90,14 @@
             definition.setSelectionList(list);
         }
     }
-    
+
     protected SelectionList buildSelectionList(
             Element widgetElement, AbstractDatatypeWidgetDefinition definition, String name)
throws Exception {
         Element selectionListElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS,
name);
-        
+
         if(selectionListElement != null && definition.getDatatype() == null)
             throw new Exception("A widget with a selection list always requires a datatype
as well! (at "+DomHelper.getLocation(selectionListElement)+" )");
-        
+
         if (selectionListElement == null)
             return null;
 

Modified: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java?rev=370138&r1=370137&r2=370138&view=diff
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java
(original)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/MultiValueFieldDefinitionBuilder.java
Wed Jan 18 05:33:35 2006
@@ -26,7 +26,7 @@
 
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception
{
         MultiValueFieldDefinition definition = new MultiValueFieldDefinition();
-        setupDefinition(widgetElement, definition);
+        setupDefinition(widgetElement, definition, true);
         definition.makeImmutable();
         return definition;
     }



Mime
View raw message