cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding JavaScriptJXPathBinding.java SimpleRepeaterJXPathBinding.java SimpleRepeaterJXPathBindingBuilder.java
Date Mon, 03 Nov 2003 17:05:02 GMT
sylvain     2003/11/03 09:05:02

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/binding
                        JavaScriptJXPathBinding.java
                        SimpleRepeaterJXPathBinding.java
                        SimpleRepeaterJXPathBindingBuilder.java
  Log:
  Fix bug in JS binding, add new "delete-if-empty" on simple-repeater
  
  Revision  Changes    Path
  1.2       +20 -22    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/JavaScriptJXPathBinding.java
  
  Index: JavaScriptJXPathBinding.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/JavaScriptJXPathBinding.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaScriptJXPathBinding.java	3 Oct 2003 13:40:41 -0000	1.1
  +++ JavaScriptJXPathBinding.java	3 Nov 2003 17:05:02 -0000	1.2
  @@ -90,28 +90,26 @@
           
           // Move to widget context
           Pointer pointer = jctx.getPointer(this.path);
  -        JXPathContext widgetCtx = jctx.getRelativeContext(pointer);
  -        if (pointer.getNode() != null) {
  -            // There are some nodes to load from
  -    
  -            // FIXME: remove this ugly hack and get the request from the Avalon context
once
  -            // binding builder are real components
  -            Request request = ObjectModelHelper.getRequest(CocoonComponentManager.getCurrentEnvironment().getObjectModel());
  -            
  -            try {
  -                Map values = new HashMap(3);
  -                values.put("widget", widget);
  -                values.put("jxpathContext", widgetCtx);
  -                values.put("jxpathPointer", pointer);
  -                
  -                JavaScriptHelper.execScript(this.loadScript, values, request);
  -                
  -            } catch(RuntimeException re) {
  -                // rethrow
  -                throw re;
  -            } catch(Exception e) {
  -                throw new CascadingRuntimeException("Error invoking JavaScript event handler",
e);
  +
  +        // FIXME: remove this ugly hack and get the request from the Avalon context once
  +        // binding builder are real components
  +        Request request = ObjectModelHelper.getRequest(CocoonComponentManager.getCurrentEnvironment().getObjectModel());
  +        
  +        try {
  +            Map values = new HashMap(3);
  +            values.put("widget", widget);
  +            values.put("jxpathPointer", pointer);
  +            if (pointer.getNode() != null) {
  +                values.put("jxpathContext", jctx.getRelativeContext(pointer));
               }
  +            
  +            JavaScriptHelper.execScript(this.loadScript, values, request);
  +            
  +        } catch(RuntimeException re) {
  +            // rethrow
  +            throw re;
  +        } catch(Exception e) {
  +            throw new CascadingRuntimeException("Error invoking JavaScript event handler",
e);
           }
       }
   
  
  
  
  1.3       +21 -12    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/SimpleRepeaterJXPathBinding.java
  
  Index: SimpleRepeaterJXPathBinding.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/SimpleRepeaterJXPathBinding.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleRepeaterJXPathBinding.java	3 Oct 2003 13:40:41 -0000	1.2
  +++ SimpleRepeaterJXPathBinding.java	3 Nov 2003 17:05:02 -0000	1.3
  @@ -74,14 +74,16 @@
       private final String rowPath;
       private final boolean clearOnLoad;
       private final JXPathBindingBase rowBinding;
  +    private final boolean deleteIfEmpty;
   
       public SimpleRepeaterJXPathBinding(
  -      String repeaterId, String repeaterPath, String rowPath, boolean clearOnLoad, JXPathBindingBase
rowBinding) {
  +      String repeaterId, String repeaterPath, String rowPath, boolean clearOnLoad, boolean
deleteIfEmpty, JXPathBindingBase rowBinding) {
           this.repeaterId = repeaterId;
           this.repeaterPath = repeaterPath;
           this.rowPath = rowPath;
           this.rowBinding = rowBinding;
           this.clearOnLoad = clearOnLoad;
  +        this.deleteIfEmpty = deleteIfEmpty;
       }
   
       public void loadFormFromModel(Widget frmModel, JXPathContext jctx) {
  @@ -129,18 +131,25 @@
           // Find the repeater
           Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
   
  -        // Move to repeater context and create the path if needed
  -        // FIXME: should avoid creating the path if repeater is empty
  -        JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath));
  +        if (repeater.getSize() == 0 && this.deleteIfEmpty) {
  +            // Repeater is empty : erase all
  +            jctx.removeAll(this.repeaterPath);
   
  -        // Delete all that is already present
  -        repeaterContext.removeAll(this.rowPath);
  -        
  -        for (int i = 0; i < repeater.getSize(); i++) {
  -            String path = this.rowPath + '[' + (i+1) + ']';
  -            Pointer rowPtr = repeaterContext.createPath(path);
  -            JXPathContext rowContext = repeaterContext.getRelativeContext(rowPtr);
  -            this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext);
  +        } else {
  +            // Repeater is not empty
  +            
  +            // Move to repeater context and create the path if needed
  +            JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath));
  +
  +            // Delete all that is already present
  +            repeaterContext.removeAll(this.rowPath);
  +
  +            for (int i = 0; i < repeater.getSize(); i++) {
  +                String path = this.rowPath + '[' + (i+1) + ']';
  +                Pointer rowPtr = repeaterContext.createPath(path);
  +                JXPathContext rowContext = repeaterContext.getRelativeContext(rowPtr);
  +                this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext);
  +            }
           }
       }
   
  
  
  
  1.3       +2 -1      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/SimpleRepeaterJXPathBindingBuilder.java
  
  Index: SimpleRepeaterJXPathBindingBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/SimpleRepeaterJXPathBindingBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleRepeaterJXPathBindingBuilder.java	3 Oct 2003 13:40:41 -0000	1.2
  +++ SimpleRepeaterJXPathBindingBuilder.java	3 Nov 2003 17:05:02 -0000	1.3
  @@ -78,10 +78,11 @@
               String parentPath = DomHelper.getAttribute(bindingElem, "parent-path");
               String rowPath = DomHelper.getAttribute(bindingElem, "row-path");
               boolean clearOnLoad = DomHelper.getAttributeAsBoolean(bindingElem, "clear-before-load",
true);
  +            boolean deleteIfEmpty = DomHelper.getAttributeAsBoolean(bindingElem, "delete-parent-if-empty",
false);
   
               JXPathBindingBase[] childBindings = assistant.makeChildBindings(bindingElem);
   
  -            return new SimpleRepeaterJXPathBinding(repeaterId, parentPath, rowPath, clearOnLoad,
  +            return new SimpleRepeaterJXPathBinding(repeaterId, parentPath, rowPath, clearOnLoad,
deleteIfEmpty,
                   new ComposedJXPathBindingBase(childBindings));
           } catch (BindingException e) {
               throw e;
  
  
  

Mime
View raw message