cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r179278 - in /cocoon/branches/BRANCH_2_1_X: ./ src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ src/blocks/forms/samples/forms/ src/blocks/forms/samples/resources/
Date Tue, 31 May 2005 21:18:17 GMT
Author: sylvain
Date: Tue May 31 14:18:17 2005
New Revision: 179278

URL: http://svn.apache.org/viewcvs?rev=179278&view=rev
Log:
New fd:true-param-value configuration for booleanfield

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/registration.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java?rev=179278&r1=179277&r2=179278&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
Tue May 31 14:18:17 2005
@@ -20,6 +20,7 @@
 import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.FormContext;
 import org.apache.cocoon.forms.event.*;
+import org.apache.cocoon.xml.AttributesImpl;
 import org.apache.cocoon.xml.XMLUtils;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -78,7 +79,9 @@
         validationError = null;
         Object oldValue = value;
         String param = formContext.getRequest().getParameter(getRequestParameterName());
-        value = Boolean.valueOf(param);
+
+        value = BooleanUtils.toBooleanObject(definition.getTrueParamValue().equals(param));
+
         if (!value.equals(oldValue)) {
             getForm().addWidgetEvent(new ValueChangedEvent(this, oldValue, value));
         }
@@ -110,10 +113,19 @@
         return BOOLEAN_FIELD_EL;
     }
 
+    protected AttributesImpl getXMLElementAttributes() {
+        AttributesImpl attrs = super.getXMLElementAttributes();
+        // Add the parameter value for true
+        attrs.addCDATAAttribute("true-value", definition.getTrueParamValue());
+        return attrs;
+    }
+
     public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws
SAXException {
         // value element
         contentHandler.startElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON
+ VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES);
-        String stringValue = String.valueOf(BooleanUtils.toBoolean(value));
+
+        String stringValue = BooleanUtils.toBoolean(value) ? definition.getTrueParamValue()
: "false";
+
         contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
         contentHandler.endElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON
+ VALUE_EL);
         // validation message element: only present if the value is not valid

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java?rev=179278&r1=179277&r2=179278&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinition.java
Tue May 31 14:18:17 2005
@@ -28,6 +28,8 @@
     private ValueChangedListener listener;
     
     private Boolean initialValue;
+    
+    private String trueParamValue = "true";
 
     public Widget createInstance() {
         return new BooleanField(this);
@@ -40,6 +42,19 @@
     
     public Boolean getInitialValue() {
         return this.initialValue;
+    }
+    
+    public void setTrueParamValue(String value) {
+        checkMutable();
+        this.trueParamValue = value;
+    }
+    
+    /**
+     * Get the parameter value that indicates a true value. Default
+     * is "<code>true</code>".
+     */
+    public String getTrueParamValue() {
+        return this.trueParamValue;
     }
     
     public void addValueChangedListener(ValueChangedListener listener) {

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java?rev=179278&r1=179277&r2=179278&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanFieldDefinitionBuilder.java
Tue May 31 14:18:17 2005
@@ -29,6 +29,7 @@
  */
 public final class BooleanFieldDefinitionBuilder extends AbstractWidgetDefinitionBuilder
{
     public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception
{
+        
         BooleanFieldDefinition definition = new BooleanFieldDefinition();
         
         super.setupDefinition(widgetElement, definition);
@@ -42,7 +43,14 @@
         Element initialValueElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS,
"initial-value", false);
         if (initialValueElement != null) {
             Boolean initialValue = Boolean.valueOf(DomHelper.getElementText(initialValueElement));
-        }        
+            definition.setInitialValue(initialValue);
+        }
+        
+        // Parameter value for true
+        Element trueParamElement = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS,
"true-param-value", false);
+        if (trueParamElement != null) {
+            definition.setTrueParamValue(DomHelper.getElementText(trueParamElement));
+        }
 
         definition.makeImmutable();
         return definition;

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/registration.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/registration.xml?rev=179278&r1=179277&r2=179278&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/registration.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/registration.xml Tue May 31
14:18:17 2005
@@ -68,6 +68,10 @@
   
     <fd:booleanfield id="spam">
       <fd:label>Send me spam</fd:label>
+      <!-- initially checked -->
+      <fd:initial-value>true</fd:initial-value>
+      <!-- request param value will be "send" when checked -->
+      <fd:true-param-value>send</fd:true-param-value>
     </fd:booleanfield>
   </fd:widgets>
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl?rev=179278&r1=179277&r2=179278&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl
Tue May 31 14:18:17 2005
@@ -302,7 +302,7 @@
       +-->
   <xsl:template match="fi:booleanfield">
     <span id="{@id}">
-      <input id="{@id}-input" type="checkbox" value="true" name="{@id}" title="{fi:hint}">
+      <input id="{@id}-input" type="checkbox" value="{@true-value}" name="{@id}" title="{fi:hint}">
         <xsl:apply-templates select="." mode="styling"/>
         <xsl:choose>
           <xsl:when test="./fi:styling[@type='hidden']">
@@ -311,7 +311,7 @@
             </xsl:if>
           </xsl:when>
           <xsl:otherwise>
-            <xsl:if test="fi:value = 'true'">
+            <xsl:if test="fi:value != 'false'">
               <xsl:attribute name="checked">checked</xsl:attribute>
             </xsl:if>
           </xsl:otherwise>
@@ -326,8 +326,8 @@
       | use text but avoids i18n problems related to hardcoding 'yes'/'no' or 'true'/'false'
       +-->
   <xsl:template match="fi:booleanfield[@state='output' or fi:styling/@type='output']"
priority="3">
-    <input id="{@id}" type="checkbox" title="{fi:hint}" disabled="disabled">
-    	  <xsl:if test="fi:value = 'true'">
+    <input id="{@id}" type="checkbox" title="{fi:hint}" disabled="disabled" value="{@true-value}">
+    	  <xsl:if test="fi:value != 'true'">
     	    <xsl:attribute name="checked">checked</xsl:attribute>
     	  </xsl:if>
     </input>

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=179278&r1=179277&r2=179278&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Tue May 31 14:18:17 2005
@@ -196,6 +196,11 @@
 
   <changes>
   <release version="@version@" date="@date@">
+     <action dev="SW" type="add">
+       CForms block: add a new <code>&lt;fd:true-param-value&gt;<code>
configuration to
+       booleanfield definitions, to allow specifying a value different from "<code>true</code>"
+       for the checkbox.
+     </action>
     <action dev="CZ" type="update">
       Set the content-length of a response when the pipeline buffers the content
       (which is the default).



Mime
View raw message