cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel Repeater.java
Date Fri, 07 May 2004 20:54:21 GMT
mpo         2004/05/07 13:54:21

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript
                        Form.js
               src/blocks/forms/java/org/apache/cocoon/forms/generation
                        template.jx
               src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2
                        Form.js
               src/blocks/forms/samples/forms carselector_form.xml
                        countryselector_form.xml
                        countryselector_success.xsp
                        form_model_gui_success.xsp form1.xml
                        form1_success.xsp carselector_success.xsp
               src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3
                        Form.js
               src/blocks/forms/samples/flow forms_flow_example.js
                        upload_example.js
               src/blocks/forms/java/org/apache/cocoon/forms/formmodel
                        Repeater.java
  Log:
  Making transition getWidget --> lookupWidget on the samples.
  Note: We will need to mention this to our users, their installations will have the same
transition.
  
  Currently kept a getWidget() on the Form.js to return the underlaying java-widget of the
Form.
  Refactored the car and country-selector to abuse the new "../" path syntax.
  
  Revision  Changes    Path
  1.10      +11 -3     cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js
  
  Index: Form.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/Form.js,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Form.js	7 May 2004 10:55:08 -0000	1.9
  +++ Form.js	7 May 2004 20:54:20 -0000	1.10
  @@ -52,16 +52,24 @@
       return this.formWidget;
   }
   
  +
  +/**
  + * Get the actual Form-Widget (the Java object)
  + */
  +Form.prototype.getWidget = function() {
  +    return this.form;
  +}
  +
   /**
    * Get a Widget (the java object) from the form.
    * If <code>name</code> is undefined, the form widget itself is returned.
    * Otherwise, the form's child widget of name <code>name</code> is returned.
    */
  -Form.prototype.getWidget = function(name) {
  +Form.prototype.lookupWidget = function(name) {
       if (name == undefined) {
           return this.form;
       } else {
  -        return this.form.getWidget(name);
  +        return this.form.lookupWidget(name);
       }
   }
   
  
  
  
  1.2       +5 -5      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/generation/template.jx
  
  Index: template.jx
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/generation/template.jx,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- template.jx	20 Mar 2004 19:29:14 -0000	1.1
  +++ template.jx	7 May 2004 20:54:21 -0000	1.2
  @@ -12,7 +12,7 @@
   
   <jx:macro name="widget" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
 
   <jx:parameter name="id"/>  
  -  <jx:set var="context_widget_" value="${context_widget_.getWidget(id)}"/>
  +  <jx:set var="context_widget_" value="${context_widget_.lookupWidget(id)}"/>
     <jx:set var="list_" value="${java.util.LinkedList()}"/>
     <jx:set var="buffer_" value="${Packages.org.apache.cocoon.forms.generation.SaxBuffer(list_)}"/>
     <jx:if test="${empty locale}">
  @@ -28,22 +28,22 @@
   <jx:macro name="repeater-widget-label" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
 
   <jx:parameter name="id"/>  
   <jx:parameter name="widget-id"/>
  -${context_widget_.getWidget(id).unwrap().generateWidgetLabel(this['widget-id'], cocoon.consumer)}
  +${context_widget_.lookupWidget(id).unwrap().generateWidgetLabel(this['widget-id'], cocoon.consumer)}
   </jx:macro>
   
   <jx:macro name="widget-label" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
   <jx:parameter name="id"/>
  -${context_widget_.getWidget(id).unwrap().generateLabel(cocoon.consumer)}
  +${context_widget_.lookupWidget(id).unwrap().generateLabel(cocoon.consumer)}
   </jx:macro>
   
   <jx:macro name="repeater-size" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
   <jx:parameter name="id"/>
  -${context_widget_.getWidget(id).unwrap().generateSize(cocoon.consumer)}
  +${context_widget_.lookupWidget(id).unwrap().generateSize(cocoon.consumer)}
   </jx:macro>
   
   <jx:macro name="repeater-widget" targetNamespace="http://apache.org/cocoon/forms/1.0#template"
xmlns:ft="http://apache.org/cocoon/forms/1.0#template">  
   <jx:parameter name="id"/>
  -  <jx:set var="repeater_" value="${context_widget_.getWidget(id)}"/>
  +  <jx:set var="repeater_" value="${context_widget_.lookupWidget(id)}"/>
     <jx:set var="lastRow_" value="${repeater_.length - 1}"/>
     <jx:forEach varStatus="loop_" begin="0" end="${lastRow_}">
         <jx:set var="context_widget_" value="${repeater_.getRow(loop_.index)}"/> 
  
  
  
  1.7       +8 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/Form.js
  
  Index: Form.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/Form.js,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Form.js	6 May 2004 14:23:04 -0000	1.6
  +++ Form.js	7 May 2004 20:54:21 -0000	1.7
  @@ -54,18 +54,24 @@
       }
   }
   
  +/**
  + * Get the actual Form-Widget (the Java object)
  + */
  +Form.prototype.getWidget = function() {
  +    return this.form;
  +}
   
   /**
    * Get a Widget from the form.
    * If <code>name</code> is undefined, the form widget itself is returned.
    * Otherwise, the form's child widget of name <code>name</code> is returned.
    */
  -Form.prototype.getWidget = function(name) {
  +Form.prototype.lookupWidget = function(name) {
       var result;
       if (name == undefined) {
           result = this.formWidget_;
       } else {
  -        result = this.formWidget_.getWidget(name);
  +        result = this.formWidget_.lookupWidget(name);
       }
       return result;
   }
  
  
  
  1.3       +6 -6      cocoon-2.1/src/blocks/forms/samples/forms/carselector_form.xml
  
  Index: carselector_form.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/forms/carselector_form.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- carselector_form.xml	5 Apr 2004 12:25:29 -0000	1.2
  +++ carselector_form.xml	7 May 2004 20:54:21 -0000	1.3
  @@ -28,7 +28,7 @@
           <javascript>
             java.lang.System.err.println("maker changed from " + event.oldValue + " to "
+ event.newValue);
             var value = event.source.value;
  -          var typewidget = event.source.parent.getWidget("type");
  +          var typewidget = event.source.lookupWidget("../type");
             if (value != null) {
               // Get the corresponding type list
               typewidget.setSelectionList("cocoon:/cars/" + value);
  @@ -43,7 +43,7 @@
             typewidget.setValue(null);
             
             // Fun with messages...
  -          var msg = event.source.parent.getWidget("message");
  +          var msg = event.source.lookupWidget("../message");
             if (value == null) {
               msg.value = "Yep. Choosing a maker is not that easy...";
             } else {
  @@ -69,8 +69,8 @@
           <javascript>
             java.lang.System.err.println("type changed to " + event.source.value);
             var value = event.source.value;
  -          var modelwidget = event.source.parent.getWidget("model");
  -          var makewidget = event.source.parent.getWidget("make");
  +          var modelwidget = event.source.lookupWidget("../model");
  +          var makewidget = event.source.lookupWidget("../make");
             if (value != null) {
               modelwidget.setSelectionList("cocoon:/cars/" + makewidget.value + "/" + value);
             } else {
  @@ -86,7 +86,7 @@
             
             // Fun with messages...
             if (value != null) {
  -            var msg = event.source.parent.getWidget("message");
  +            var msg = event.source.lookupWidget("../message");
               if (event.oldValue == null) {
                 msg.value = "A " + makewidget.value + " " + value + " is a very good choice.";
               } else {
  @@ -109,7 +109,7 @@
           <javascript>
             var value = event.source.value;
             if (value != null) {
  -            event.source.parent.getWidget("message").setValue("Model " + value + " is a
great car!");
  +            event.source.lookupWidget("../message").setValue("Model " + value + " is a
great car!");
             } else {
               // Reset value
               event.source.value = null;
  
  
  
  1.3       +2 -2      cocoon-2.1/src/blocks/forms/samples/forms/countryselector_form.xml
  
  Index: countryselector_form.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/forms/countryselector_form.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- countryselector_form.xml	5 Apr 2004 12:25:29 -0000	1.2
  +++ countryselector_form.xml	7 May 2004 20:54:21 -0000	1.3
  @@ -39,7 +39,7 @@
   	      <javascript>
   	        java.lang.System.err.println("Residence changed from " + event.oldValue + " to
" + event.newValue);
   	        var value = event.source.value;
  -	        var typewidget = event.source.parent.getWidget("country");
  +	        var typewidget = event.source.lookupWidget("../country");
   	        if (value == "us") {
   	          typewidget.setSelectionList(states, "key", "value");
   	        }
  @@ -71,7 +71,7 @@
   	      <javascript>
   	        var value = event.source.value;
   	        if (value != null) {
  -	          event.source.parent.getWidget("message").setValue("So you live in  " + value
+ " ?");
  +	          event.source.lookupWidget("../message").setValue("So you live in  " + value
+ " ?");
   	        } else {
   	          // Reset value
   	          event.source.value = null;
  
  
  
  1.2       +2 -2      cocoon-2.1/src/blocks/forms/samples/forms/countryselector_success.xsp
  
  Index: countryselector_success.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/forms/countryselector_success.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- countryselector_success.xsp	9 Mar 2004 10:33:48 -0000	1.1
  +++ countryselector_success.xsp	7 May 2004 20:54:21 -0000	1.2
  @@ -27,8 +27,8 @@
         <xsp:logic>
           // get reference to form and some of the widgets on it
           Form form = (Form)request.getAttribute("countryselectorform");
  -        Field usnonus = (Field)form.getWidget("us-nonus");
  -        Field country = (Field)form.getWidget("country");
  +        Field usnonus = (Field)form.lookupWidget("us-nonus");
  +        Field country = (Field)form.lookupWidget("country");
         </xsp:logic>
   
         You selected: <xsp:expr>usnonus.getValue()</xsp:expr>,
  
  
  
  1.3       +2 -2      cocoon-2.1/src/blocks/forms/samples/forms/form_model_gui_success.xsp
  
  Index: form_model_gui_success.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/forms/form_model_gui_success.xsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- form_model_gui_success.xsp	12 Apr 2004 14:05:09 -0000	1.2
  +++ form_model_gui_success.xsp	7 May 2004 20:54:21 -0000	1.3
  @@ -31,7 +31,7 @@
         <xsp:logic>
           // get reference to form and some of the widgets on it
           Form form = (Form)request.getAttribute("form_model_gui");
  -        Repeater repeater = (Repeater)form.getWidget("widgets");
  +        Repeater repeater = (Repeater)form.lookupWidget("widgets");
         </xsp:logic>
   
         Repeater has <xsp:expr>repeater.getSize()</xsp:expr> row(s).
  
  
  
  1.7       +5 -5      cocoon-2.1/src/blocks/forms/samples/forms/form1.xml
  
  Index: form1.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/forms/form1.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- form1.xml	7 May 2004 10:55:08 -0000	1.6
  +++ form1.xml	7 May 2004 20:54:21 -0000	1.7
  @@ -26,7 +26,7 @@
       <!-- This demonstrates form level validation -->
       <fd:javascript>
         var success = true;
  -      var price = widget.getWidget("dieselprice");
  +      var price = widget.lookupWidget("dieselprice");
         if (price.value &lt; 1) {
             price.setValidationError(new Packages.org.apache.cocoon.forms.validation.ValidationError("It
can not be that low!", false));
             success = false;
  @@ -115,7 +115,7 @@
             java.lang.System.err.println("Was here!");
             var newValue = event.source.value;
             if (newValue != null) {
  -            var number2 = event.source.parent.getWidget("number2");
  +            var number2 = event.source.parent.lookupWidget("number2");
               if (number2.value == null) {
                 number2.setValue(new java.lang.Long(newValue.intValue() + 1));
               }
  @@ -261,10 +261,10 @@
               // Get the row
               var row = widget.getRow(i);
               // Compute a key combining the first and last name
  -            var key = row.getWidget("firstname").value + "/" + row.getWidget("lastname").value;
  +            var key = row.lookupWidget("firstname").value + "/" + row.lookupWidget("lastname").value;
               if (list.contains(key)) {
                 // already in the list
  -              row.getWidget("firstname").setValidationError(new Packages.org.apache.cocoon.forms.validation.ValidationError("Duplicate
contact name", false));
  +              row.lookupWidget("firstname").setValidationError(new Packages.org.apache.cocoon.forms.validation.ValidationError("Duplicate
contact name", false));
                 success = false;
                 break; // no need to continue
               }
  
  
  
  1.2       +3 -3      cocoon-2.1/src/blocks/forms/samples/forms/form1_success.xsp
  
  Index: form1_success.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/forms/form1_success.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- form1_success.xsp	9 Mar 2004 10:33:48 -0000	1.1
  +++ form1_success.xsp	7 May 2004 20:54:21 -0000	1.2
  @@ -27,9 +27,9 @@
         <xsp:logic>
           // get reference to form and some of the widgets on it
           Form form = (Form)request.getAttribute("form1");
  -        Field field = (Field)form.getWidget("email");
  -        BooleanField booleanField = (BooleanField)form.getWidget("somebool");
  -        Field field2 = (Field)((Repeater)form.getWidget("contacts")).getWidget(1, "firstname");
  +        Field field = (Field)form.lookupWidget("email");
  +        BooleanField booleanField = (BooleanField)form.lookupWidget("somebool");
  +        Field field2 = (Field)((Repeater)form.lookupWidget("contacts")).getWidget(1, "firstname");
         </xsp:logic>
   
         email has the following value:
  
  
  
  1.2       +3 -3      cocoon-2.1/src/blocks/forms/samples/forms/carselector_success.xsp
  
  Index: carselector_success.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/forms/carselector_success.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- carselector_success.xsp	9 Mar 2004 10:33:48 -0000	1.1
  +++ carselector_success.xsp	7 May 2004 20:54:21 -0000	1.2
  @@ -27,9 +27,9 @@
         <xsp:logic>
           // get reference to form and some of the widgets on it
           Form form = (Form)request.getAttribute("carselectorform");
  -        Field make = (Field)form.getWidget("make");
  -        Field type = (Field)form.getWidget("type");
  -        Field model = (Field)form.getWidget("model");
  +        Field make = (Field)form.lookupWidget("make");
  +        Field type = (Field)form.lookupWidget("type");
  +        Field model = (Field)form.lookupWidget("model");
         </xsp:logic>
   
         You selected: maker <xsp:expr>make.getValue()</xsp:expr>,
  
  
  
  1.3       +8 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/Form.js
  
  Index: Form.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/Form.js,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Form.js	6 May 2004 14:23:04 -0000	1.2
  +++ Form.js	7 May 2004 20:54:21 -0000	1.3
  @@ -55,17 +55,23 @@
       }
   }
   
  +/**
  + * Get the actual Form-Widget (the Java object)
  + */
  +Form.prototype.getWidget = function() {
  +    return this.form;
  +}
   
   /**
    * Get a Widget (the java object) from the form.
    * If <code>name</code> is undefined, the form widget itself is returned.
    * Otherwise, the form's child widget of name <code>name</code> is returned.
    */
  -Form.prototype.getWidget = function(name) {
  +Form.prototype.lookupWidget = function(name) {
       if (name == undefined) {
           return this.form;
       } else {
  -        return this.form.getWidget(name);
  +        return this.form.lookupWidget(name);
       }
   }
   
  
  
  
  1.3       +1 -1      cocoon-2.1/src/blocks/forms/samples/flow/forms_flow_example.js
  
  Index: forms_flow_example.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/flow/forms_flow_example.js,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- forms_flow_example.js	11 Mar 2004 02:56:33 -0000	1.2
  +++ forms_flow_example.js	7 May 2004 20:54:21 -0000	1.3
  @@ -46,7 +46,7 @@
   
   function selectCar() {
       var form = new Form("forms/carselector_form.xml");
  -    form.getWidget("make").setValue(cocoon.parameters.defaultMake);
  +    form.lookupWidget("make").setValue(cocoon.parameters.defaultMake);
       form.showForm("carselector-display-pipeline");
       cocoon.request.setAttribute("carselectorform", form.getWidget());
       cocoon.sendPage("carselector-success-pipeline.xsp");
  
  
  
  1.3       +3 -3      cocoon-2.1/src/blocks/forms/samples/flow/upload_example.js
  
  Index: upload_example.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/flow/upload_example.js,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- upload_example.js	11 Mar 2004 02:56:33 -0000	1.2
  +++ upload_example.js	7 May 2004 20:54:21 -0000	1.3
  @@ -25,8 +25,8 @@
       cocoon.sendPage("upload-success-pipeline.jx",
           {
               uploadContent: handleUpload(form), 
  -            username: form.getWidget("user").getValue(),
  -            filename: form.getWidget("upload").getValue().getHeaders().get("filename")
  +            username: form.lookupWidget("user").getValue(),
  +            filename: form.lookupWidget("upload").getValue().getHeaders().get("filename")
           }
       );
   }
  @@ -35,7 +35,7 @@
   
     var buf = new java.lang.StringBuffer();
     
  -  var uploadWidget = form.getWidget("upload");
  +  var uploadWidget = form.lookupWidget("upload");
     if (uploadWidget.getValue() != null) {
       var stream = uploadWidget.getValue().getInputStream();
       var reader = new java.io.BufferedReader(new java.io.InputStreamReader(stream));
  
  
  
  1.14      +2 -26     cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
  
  Index: Repeater.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Repeater.java	7 May 2004 16:43:42 -0000	1.13
  +++ Repeater.java	7 May 2004 20:54:21 -0000	1.14
  @@ -177,31 +177,7 @@
           RepeaterRow row = (RepeaterRow)rows.get(rowIndex);
           return row.getChild(id);
       }
  -//
  -//    public boolean hasWidget(String id) {
  -//        int row; 
  -//        try { 
  -//            row = Integer.parseInt(id);
  -//        } catch (NumberFormatException e) {
  -//            // TODO: Use i18n.
  -//            throw new RuntimeException("Repeater: Row id is not a valid integer: " +
id);
  -//        }
  -//        return row >= 0 && row < rows.size();
  -//    }
  -
  -    //TODO: consider removing when this method is removed 
  -    // from the Widget interface.
  -    public Widget getWidget(String id) {
  -        int row; 
  -        try { 
  -            row = Integer.parseInt(id);
  -        } catch (NumberFormatException e) {
  -            // TODO: Use i18n.
  -            throw new RuntimeException("Repeater: Row id is not a valid integer: " + id);
  -        }
  -        return (RepeaterRow)rows.get(row);
  -    }
  -
  +    
       public void readFromRequest(FormContext formContext) {
           // read number of rows from request, and make an according number of rows
           String sizeParameter = formContext.getRequest().getParameter(getRequestParameterName()
+ ".size");
  
  
  

Mime
View raw message