cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jer...@apache.org
Subject svn commit: r694351 - in /cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms: java/org/apache/cocoon/forms/generation/JXMacrosHelper.java resources/org/apache/cocoon/forms/generation/jx-macros.xml
Date Thu, 11 Sep 2008 17:04:32 GMT
Author: jeremy
Date: Thu Sep 11 10:04:30 2008
New Revision: 694351

URL: http://svn.apache.org/viewvc?rev=694351&view=rev
Log:
JXMacro generation adjusted to output a Repeater as repeater-widget, adjusted to output all
bu ids with a :bu suffix, to avoid id clashes on the browser

Modified:
    cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
    cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/resources/org/apache/cocoon/forms/generation/jx-macros.xml

Modified: cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java?rev=694351&r1=694350&r2=694351&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
(original)
+++ cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
Thu Sep 11 10:04:30 2008
@@ -159,7 +159,7 @@
 
     private void startBuReplace(String id) throws SAXException {
         AttributesImpl attr = new AttributesImpl();
-        attr.addCDATAAttribute("id", id);
+        attr.addCDATAAttribute("id", id + ":bu"); // add suffix to avoid id conflict with
page widgets needing an id
         this.cocoonConsumer.startElement(BrowserUpdateTransformer.BU_NSURI, "replace", "bu:replace",
attr);
     }
 
@@ -277,22 +277,80 @@
      *
      * @param path widget path
      * @param ajaxAware distinguishes between <ft:repeater-widget> and <ft:repeater>.
+     * @param attributes the model attributes
      * @return true if the repeater template is to be executed
      * @throws SAXException
      */
-    public boolean pushRepeater(String path, boolean ajaxAware) throws SAXException {
+    public boolean pushRepeater(String path, boolean ajaxAware, Map attributes) throws SAXException
{
         if (!ajaxAware && this.ajaxTemplate) {
             throw new IllegalStateException("Cannot use <ft:repeater-widget> in an
Ajax form");
         }
         boolean result = pushWidget(path, true);
         if (result && !(peekWidget() instanceof Repeater)) {
             throw new IllegalArgumentException("Widget " + peekWidget() + " is not a repeater");
+        } else if (peekWidget() instanceof Repeater) {
+					Repeater repeater = (Repeater)peekWidget();
+        	AttributesImpl attrs = new AttributesImpl();
+					
+					if (repeater.getOrderable()) attrs.addCDATAAttribute("orderable", Boolean.toString(repeater.getOrderable()));
+					Iterator it = repeater.getAcceptTypes().iterator();
+					if (it.hasNext()) {
+						StringBuffer type = new StringBuffer();
+						while (it.hasNext()) {
+							String value = (String)it.next();
+							type.append(value);
+							if (it.hasNext() && !"".equals(value)) type.append(',');
+						}
+						attrs.addCDATAAttribute("acceptType", type.toString());
+					}
+					it = repeater.getRowTypes().iterator();
+					if (it.hasNext()) {
+						StringBuffer type = new StringBuffer();
+						while (it.hasNext()) {
+							String value = (String)it.next();
+							type.append(value);
+							if (it.hasNext() && !"".equals(value)) type.append(',');
+						}
+						attrs.addCDATAAttribute("rowType", type.toString());
+					}
+					it = repeater.getAllowed().iterator();
+					if (it.hasNext()) {
+						StringBuffer type = new StringBuffer();
+						while (it.hasNext()) {
+							String value = (String)it.next();
+							type.append(value);
+							if (it.hasNext() && !"".equals(value)) type.append(',');
+						}
+						attrs.addCDATAAttribute("dndAllow", type.toString());
+					}
+
+        	// copy attributes from Template
+					Iterator iter = attributes.entrySet().iterator();
+					while(iter.hasNext()) {
+							Map.Entry entry = (Map.Entry)iter.next();
+							final String attrName = (String)entry.getKey();
+							if (!"id".equals(attrName)) attrs.addCDATAAttribute(attrName, (String)entry.getValue());
+					}
+					attrs.addCDATAAttribute("id", repeater.getFullName());
+					this.cocoonConsumer.startPrefixMapping(FormsConstants.INSTANCE_PREFIX, FormsConstants.INSTANCE_NS);
+					this.cocoonConsumer.startElement(FormsConstants.INSTANCE_NS,
+                                         "repeater-widget",
+                                         FormsConstants.INSTANCE_PREFIX_COLON + "repeater-widget",
+                                         attrs);
         }
         // the child widgets of the repeater never update the label
         this.labelStack.push(Boolean.FALSE);
         return result;
     }
 
+    public void popRepeater() throws SAXException {
+        this.cocoonConsumer.endElement(FormsConstants.INSTANCE_NS,
+                                       "repeater-widget",
+                                       FormsConstants.INSTANCE_PREFIX_COLON + "repeater-widget");
+        this.cocoonConsumer.endPrefixMapping(FormsConstants.INSTANCE_PREFIX);
+        popWidget();
+    }
+
     /**
      * Get a child widget of a given widget, throwing an exception if no such child exists.
      *

Modified: cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/resources/org/apache/cocoon/forms/generation/jx-macros.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/resources/org/apache/cocoon/forms/generation/jx-macros.xml?rev=694351&r1=694350&r2=694351&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/resources/org/apache/cocoon/forms/generation/jx-macros.xml
(original)
+++ cocoon/branches/BRANCH_2_1_X-dojo1_1/src/blocks/forms/resources/org/apache/cocoon/forms/generation/jx-macros.xml
Thu Sep 11 10:04:30 2008
@@ -229,33 +229,33 @@
 
     <jx:macro name="repeater" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
       <jx:parameter name="id"/>
-      <jx:if test="${cformsHelper.pushRepeater(id, true)}">
-        <jx:set var="repeater" value="${cformsHelper.peekWidget()}"/>
-        <jx:set var="widget" value="${cformsHelper.peekWidget()}"/>
-        <jx:evalBody/>
-        <jx:set var="cformsDummy" value="${cformsHelper.popWidget()}"/>
+      <jx:if test="${cformsHelper.pushRepeater(id, true, macro.arguments)}">
+				<jx:set var="repeater" value="${cformsHelper.peekWidget()}"/>
+				<jx:set var="widget" value="${cformsHelper.peekWidget()}"/>
+				<jx:evalBody/>
+				<jx:set var="cformsDummy" value="${cformsHelper.popRepeater()}"/>
       </jx:if>
     </jx:macro>
 
     <jx:macro name="repeater-rows" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
-        <jx:forEach varStatus="repeaterLoop" begin="0" end="${repeater.getSize() - 1}">
-          <jx:if test="#{pushContainer($cformsHelper, java.lang.Integer.toString($repeaterLoop/index))}">
-            <jx:set var="widget" value="${cformsHelper.peekWidget()}"/>
-            <jx:evalBody/>
-            <jx:set var="cformsDummy" value="${cformsHelper.popWidget()}"/>
-          </jx:if>
-        </jx:forEach>
+      <jx:forEach varStatus="repeaterLoop" begin="0" end="${repeater.getSize() - 1}">
+        <jx:if test="#{pushContainer($cformsHelper, java.lang.Integer.toString($repeaterLoop/index))}">
+          <jx:set var="widget" value="${cformsHelper.peekWidget()}"/>
+          <jx:evalBody/>
+          <jx:set var="cformsDummy" value="${cformsHelper.popWidget()}"/>
+        </jx:if>
+      </jx:forEach>
     </jx:macro>
 
     <jx:macro name="tree" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
       <jx:parameter name="id"/>
       <jx:if test="${cformsHelper.pushContainer(id)}">
         <jx:set var="widget" value="${cformsHelper.peekWidget()}"/>
-          <jx:set var="treeWidget" value="${widget}"/>
+        <jx:set var="treeWidget" value="${widget}"/>
 	      <jx:set var="treeNode" value="${cformsHelper.createWalker()}"/>
 	      <jx:evalBody/>
-          <jx:set var="cformsDummy" value="${cformsHelper.popWidget()}"/>
-	  </jx:if>
+        <jx:set var="cformsDummy" value="${cformsHelper.popWidget()}"/>
+	    </jx:if>
     </jx:macro>
 
     <jx:macro name="tree-nodes" targetNamespace="http://apache.org/cocoon/forms/1.0#template">



Mime
View raw message