You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Gary Larsen <ga...@envisn.com> on 2007/10/23 15:10:01 UTC

CForms repeater with Ajax problem

I'm using Cocoon 2.1.9.  I have a repeater grid where each row contains a
booleanfield to select a row.

 

My problem is I only want one row selected at a time.  Without Ajax the
on-change event I created will successfully toggle off other rows when one
is selected.  With Ajax turned on it seems like there is a cascade effect
going on, the result is the other rows are not being turned off.

 

Perhaps there is another way to implement a grid like this which will work
with Ajax?

 

Thanks for any suggestions.

gary


RE: CForms repeater with Ajax problem

Posted by Gary Larsen <ga...@envisn.com>.
Great!   I'll give it a go.

 

Thanks,

gary

 

  _____  

From: Michel Gomis [mailto:cle2treize@gmail.com] 
Sent: Friday, October 26, 2007 10:47 AM
To: users@cocoon.apache.org
Subject: Re: CForms repeater with Ajax problem

 


Hi Gary,
It's for 2.1.9. We just overrided some *-styling.xsl files for our own
puropose. 
<table dojoType="CFormsRepeater" class="list" multiple="false"
select="select" width="100%"> 

class="list" and width="100%" are is for Html/Css layout, it's optional !
multiple="false" refers to CFormsRepeater new property

On 10/26/07, Gary Larsen <ga...@envisn.com> wrote:

Hi Michel,

 

Thanks for the code example.  Could you tell me what Cocoon versions this is
compatible with?  From the template code it looks like it's greater the
2.1.9 I'm currently using?

 

Thanks,

gary 

 


Hi,
I think you can do that by overriding cocoon's CFormsRepeater.js file.



 


Re: CForms repeater with Ajax problem

Posted by Michel Gomis <cl...@gmail.com>.
Hi Gary,
It's for 2.1.9. We just overrided some *-styling.xsl files for our own
puropose.
<table dojoType="CFormsRepeater" class="list" multiple="false"
select="select" width="100%">

class="list" and width="100%" are is for Html/Css layout, it's optional !
multiple="false" refers to CFormsRepeater new property

On 10/26/07, Gary Larsen <ga...@envisn.com> wrote:
>
>  Hi Michel,
>
>
>
> Thanks for the code example.  Could you tell me what Cocoon versions this
> is compatible with?  From the template code it looks like it's greater the
> 2.1.9 I'm currently using?
>
>
>
> Thanks,
>
> gary
>
>
>
>
> Hi,
> I think you can do that by overriding cocoon's CFormsRepeater.js file.
>
>
>

RE: CForms repeater with Ajax problem

Posted by Gary Larsen <ga...@envisn.com>.
Hi Michel,

 

Thanks for the code example.  Could you tell me what Cocoon versions this is
compatible with?  From the template code it looks like it's greater the
2.1.9 I'm currently using?

 

Thanks,

gary

 


Hi,
I think you can do that by overriding cocoon's CFormsRepeater.js file.





Re: CForms repeater with Ajax problem

Posted by Michel Gomis <cl...@gmail.com>.
Hi,
I think you can do that by overriding cocoon's CFormsRepeater.js file.

1°/ Put a copy of cocoon's CFormsRepeater.js in
<WebContent>/resources/forms/js

2°/ Modify the new added file so that you can choose multiple or single row
selection:
dojo.lang.extend(cocoon.forms.CFormsRepeater, {
    // Properties
    orderable: false,
    multiple: true, // true as default value, as multiple selection is the
actual behaviour

3°/ Modifiy the selectRow method
selectRow: function(e, row, idx) {
        if (this.isValidEvent(e)) {
            var selectInput = dojo.byId(row.getAttribute("id") + "." +
this.select + ":input");
              var selected = selectInput.checked ? false : true;
            // Toggle selection
            this.setChecked(selectInput, selected);
            // And update CSS class accordingly
            (selectInput.checked ? dojo.html.prependClass :
dojo.html.removeClass)(row, "forms-row-selected");
              if (selected && !this.multiple) {
                  // Deselect previously selected row, if any
                  var otherRow;
                for (var otherIdx = 0; otherRow = dojo.byId(this.id + "." +
otherIdx); otherIdx++) {
                    if (otherIdx == idx) continue;
                    var otherSelect = dojo.byId(otherRow.getAttribute("id")
+ "." + this.select + ":input");
                    if (otherSelect.checked) {
                        // Found it
                        dojo.html.removeClass(otherRow,
"forms-row-selected");
                        this.setChecked(otherSelect, false);
                        break; // finished (single selection)
                    }
                }
              }
        }
    },

    setChecked: function(input, value) {
        input.checked = value;
        if (input.onchange) {
            input.onchange();
        }
    }

4°/ Be sure you have a "select" booleanfield in your form, referenced in
your template :
<fd:repeater id="myRepeater">
  <fd:widgets>
    <fd:booleanfield id="select" />

template :
<table dojoType="CFormsRepeater" class="list" multiple="false"
select="select" width="100%">
  ...
  <ft:repeater-rows>
    <ft:widget id="select" style="display:none" />

5°/ As CFormsRepeater is lodaed in the web browser by dojo's XmlHttpRequest
based system, don't forget to empty your browser cache after every change in
CFormsRepeater.js

RE: CForms repeater with Ajax problem

Posted by Robby Pelssers <ro...@agp.nl>.
Hi Gary,
 
It MIGHT (capital letters) have something to do with the way your
template is organized.  I know out of experience that a webpage with a
lot of form-widgets works like a charm whith the attribute ajax=false
but when setting it to true you have to keep some things in mind like
for instance that a container widget MUST enclose a container element.
 
 http://cocoon.apache.org/2.1/userdocs/ajax.html
 
 
If you could sent the snippet i will take a brieve look at it.
 
Cheers,
Robby
 

________________________________

Van: Gary Larsen [mailto:gary.larsen@envisn.com] 
Verzonden: vrijdag, oktober 2007 15:13
Aan: users@cocoon.apache.org
Onderwerp: RE: CForms repeater with Ajax problem



Thanks Robby,

 

II tried the suggested change but still no luck.  I may post this to the
dev list later.  Maybe this is a bug discovered in a later version but
have not been able to find info on that.

 

Thanks,

gary

 

 

Could you give it a try by using following snippet?

 

<fd:booleanfield id="archiveVersionSelect">

    <fd:on-value-changed>

        <fd:javascript>

            var source = event.getSourceWidget();

          //if checkbox checked we need to take action -> set other
checkboxes to false

          if (source.getValue().booleanValue()) {

              var row = source.getParent();

              var rowId = row.getId();

              var repeater = row.getParent();

               //don't check state of other checkboxes...just set them
to false

               for (var i = 0; i &lt; repeater.getSize(); i++) {

                   if (i != rowId) {

 
repeater.getRow(i).lookupWidget("archiveVersionSelect").setValue(false);

                   }

               } 

          }

 

        </fd:javascript>

     </fd:on-value-changed>

</fd:booleanfield>

 

Cheers,

Robby Pelssers

 

------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
----------

 

Hi Robin,

 

Not as much luck with this one but I can live without Ajax if this is
not possible.  Setting the widget to invisible or disabled before
setValue() had no effect on the Ajax handling.

 

If you have the time to take a look, the code below works without Ajax,
making sure the unselected row widgets are set to false.  

 

<fd:booleanfield id="archiveVersionSelect">

    <fd:on-value-changed>

        <fd:javascript>

            var source = event.getSourceWidget();

            var row = source.getParent();

            var rownum = row.getName();

            cocoon.log.warn("source row: " + rownum + " value: " +
source.getValue());

            if (source.getValue() == 'true') {

                var repeater = row.getParent();

                for (var i = 0; i &lt; repeater.getSize(); i++){

                    if (i != rownum) {

                        if
(repeater.getRow(i).getChild("archiveVersionSelect").getValue() ==
'true') {

                            cocoon.log.warn("row set to false: " + i);

 
repeater.getRow(i).getChild("archiveVersionSelect").setValue(false)

                        }

                    }

                }

            }

        </fd:javascript>

     </fd:on-value-changed>

</fd:booleanfield>

 

Here's the log (without Ajax) where initially row 0 is true and row 1 is
clicked:

 

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row:
1 value: true

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - row set to
false: 0

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row:
0 value: false

 

This is the log with Ajax:

 

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row:
1 value: true

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - row set to
false: 0

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row:
0 value: false

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row:
0 value: true

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - row set to
false: 1

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row:
1 value: false

 

Even though the log says rows 0 and 1 are set to false they are still
checked on the screen.  

 

Thanks,

gary

 

________________________________

From: Robin Wyles [mailto:rob@robinwyles.com] 
Sent: Tuesday, October 23, 2007 10:43 AM
To: users@cocoon.apache.org
Subject: Re: CForms repeater with Ajax problem

 

Gary, me again!

 

Quick thought - have you tried setting the state of the repeater to
invisible at the start of your action triggered by the on-change event,
and then back to active again at the end? I've often found this to sort
out ajax updates in a repeater where you are updating widgets in
different rows.

 

If this doesn't help maybe you could post the relevant parts of your
form definition and template and the action code too.

 

Robin

 

On 23 Oct 2007, at 15:10, Gary Larsen wrote:

 

I'm using Cocoon 2.1.9.  I have a repeater grid where each row contains
a booleanfield to select a row.

 

My problem is I only want one row selected at a time.  Without Ajax the
on-change event I created will successfully toggle off other rows when
one is selected.  With Ajax turned on it seems like there is a cascade
effect going on, the result is the other rows are not being turned off.

 

Perhaps there is another way to implement a grid like this which will
work with Ajax?

 

Thanks for any suggestions.

gary

 

 


[ANN]VTD-XML 2.2

Posted by jimmy Zhang <cr...@comcast.net>.
XimpleWare is proud to announce the the release of version 2.2 of VTD-XML, the next generation XML parsers/indexer/slicer/editor. This release significantly expands VTD-XML's ability to slice, split, edit and incrementally update the XML documents. To this end, we introduce the concept of namespace-compensated element fragment. This release also adds VTD+XML index writing capability to the VTD Navigator class. Other enhancements in this release include index size pre-computation, support for HTTP get, and some bug fixes.



To download the latest release, please go to http://sourceforge.net/project/showfiles.php?group_id=110612.

RE: CForms repeater with Ajax problem

Posted by Gary Larsen <ga...@envisn.com>.
Thanks Robby,

 

II tried the suggested change but still no luck.  I may post this to the dev
list later.  Maybe this is a bug discovered in a later version but have not
been able to find info on that.

 

Thanks,

gary

 

 

Could you give it a try by using following snippet?

 

<fd:booleanfield id="archiveVersionSelect">

    <fd:on-value-changed>

        <fd:javascript>

            var source = event.getSourceWidget();

          //if checkbox checked we need to take action -> set other
checkboxes to false

          if (source.getValue().booleanValue()) {

              var row = source.getParent();

              var rowId = row.getId();

              var repeater = row.getParent();

               //don't check state of other checkboxes...just set them to
false

               for (var i = 0; i &lt; repeater.getSize(); i++) {

                   if (i != rowId) {

 
repeater.getRow(i).lookupWidget("archiveVersionSelect").setValue(false);

                   }

               } 

          }

 

        </fd:javascript>

     </fd:on-value-changed>

</fd:booleanfield>

 

Cheers,

Robby Pelssers

 

----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------------------------------------------

 

Hi Robin,

 

Not as much luck with this one but I can live without Ajax if this is not
possible.  Setting the widget to invisible or disabled before setValue() had
no effect on the Ajax handling.

 

If you have the time to take a look, the code below works without Ajax,
making sure the unselected row widgets are set to false.  

 

<fd:booleanfield id="archiveVersionSelect">

    <fd:on-value-changed>

        <fd:javascript>

            var source = event.getSourceWidget();

            var row = source.getParent();

            var rownum = row.getName();

            cocoon.log.warn("source row: " + rownum + " value: " +
source.getValue());

            if (source.getValue() == 'true') {

                var repeater = row.getParent();

                for (var i = 0; i &lt; repeater.getSize(); i++){

                    if (i != rownum) {

                        if
(repeater.getRow(i).getChild("archiveVersionSelect").getValue() == 'true') {

                            cocoon.log.warn("row set to false: " + i);

 
repeater.getRow(i).getChild("archiveVersionSelect").setValue(false)

                        }

                    }

                }

            }

        </fd:javascript>

     </fd:on-value-changed>

</fd:booleanfield>

 

Here's the log (without Ajax) where initially row 0 is true and row 1 is
clicked:

 

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row: 1
value: true

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - row set to
false: 0

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row: 0
value: false

 

This is the log with Ajax:

 

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row: 1
value: true

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - row set to
false: 0

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row: 0
value: false

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row: 0
value: true

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - row set to
false: 1

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row: 1
value: false

 

Even though the log says rows 0 and 1 are set to false they are still
checked on the screen.  

 

Thanks,

gary

 

  _____  

From: Robin Wyles [mailto:rob@robinwyles.com] 
Sent: Tuesday, October 23, 2007 10:43 AM
To: users@cocoon.apache.org
Subject: Re: CForms repeater with Ajax problem

 

Gary, me again!

 

Quick thought - have you tried setting the state of the repeater to
invisible at the start of your action triggered by the on-change event, and
then back to active again at the end? I've often found this to sort out ajax
updates in a repeater where you are updating widgets in different rows.

 

If this doesn't help maybe you could post the relevant parts of your form
definition and template and the action code too.

 

Robin

 

On 23 Oct 2007, at 15:10, Gary Larsen wrote:

 

I'm using Cocoon 2.1.9.  I have a repeater grid where each row contains a
booleanfield to select a row.

 

My problem is I only want one row selected at a time.  Without Ajax the
on-change event I created will successfully toggle off other rows when one
is selected.  With Ajax turned on it seems like there is a cascade effect
going on, the result is the other rows are not being turned off.

 

Perhaps there is another way to implement a grid like this which will work
with Ajax?

 

Thanks for any suggestions.

gary

 

 


RE: CForms repeater with Ajax problem

Posted by Robby Pelssers <ro...@agp.nl>.
 
Hi Gary,
 
Could you give it a try by using following snippet?
 
<fd:booleanfield id="archiveVersionSelect">

    <fd:on-value-changed>

        <fd:javascript>

            var source = event.getSourceWidget();

           //if checkbox checked we need to take action -> set other
checkboxes to false

           if (source.getValue().booleanValue()) {

               var row = source.getParent();

               var rowId = row.getId();

               var repeater = row.getParent();

               //don't check state of other checkboxes...just set them
to false

               for (var i = 0; i &lt; repeater.getSize(); i++) {

                   if (i != rowId) {

 
repeater.getRow(i).lookupWidget("archiveVersionSelect").setValue(false);

                   }

               } 

           }

        </fd:javascript>

     </fd:on-value-changed>

</fd:booleanfield>

 
Cheers,
Robby Pelssers
 
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
----------
 

Hi Robin,

 

Not as much luck with this one but I can live without Ajax if this is
not possible.  Setting the widget to invisible or disabled before
setValue() had no effect on the Ajax handling.

 

If you have the time to take a look, the code below works without Ajax,
making sure the unselected row widgets are set to false.  

 

<fd:booleanfield id="archiveVersionSelect">

    <fd:on-value-changed>

        <fd:javascript>

            var source = event.getSourceWidget();

            var row = source.getParent();

            var rownum = row.getName();

            cocoon.log.warn("source row: " + rownum + " value: " +
source.getValue());

            if (source.getValue() == 'true') {

                var repeater = row.getParent();

                for (var i = 0; i &lt; repeater.getSize(); i++){

                    if (i != rownum) {

                        if
(repeater.getRow(i).getChild("archiveVersionSelect").getValue() ==
'true') {

                            cocoon.log.warn("row set to false: " + i);

 
repeater.getRow(i).getChild("archiveVersionSelect").setValue(false)

                        }

                    }

                }

            }

        </fd:javascript>

     </fd:on-value-changed>

</fd:booleanfield>

 

Here's the log (without Ajax) where initially row 0 is true and row 1 is
clicked:

 

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row:
1 value: true

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - row set to
false: 0

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row:
0 value: false

 

This is the log with Ajax:

 

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row:
1 value: true

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - row set to
false: 0

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row:
0 value: false

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row:
0 value: true

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - row set to
false: 1

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row:
1 value: false

 

Even though the log says rows 0 and 1 are set to false they are still
checked on the screen.  

 

Thanks,

gary

 

________________________________

From: Robin Wyles [mailto:rob@robinwyles.com] 
Sent: Tuesday, October 23, 2007 10:43 AM
To: users@cocoon.apache.org
Subject: Re: CForms repeater with Ajax problem

 

Gary, me again!

 

Quick thought - have you tried setting the state of the repeater to
invisible at the start of your action triggered by the on-change event,
and then back to active again at the end? I've often found this to sort
out ajax updates in a repeater where you are updating widgets in
different rows.

 

If this doesn't help maybe you could post the relevant parts of your
form definition and template and the action code too.

 

Robin

 

On 23 Oct 2007, at 15:10, Gary Larsen wrote:





I'm using Cocoon 2.1.9.  I have a repeater grid where each row contains
a booleanfield to select a row.

 

My problem is I only want one row selected at a time.  Without Ajax the
on-change event I created will successfully toggle off other rows when
one is selected.  With Ajax turned on it seems like there is a cascade
effect going on, the result is the other rows are not being turned off.

 

Perhaps there is another way to implement a grid like this which will
work with Ajax?

 

Thanks for any suggestions.

gary





 


RE: CForms repeater with Ajax problem

Posted by Gary Larsen <ga...@envisn.com>.
Hi Robin,

 

Not as much luck with this one but I can live without Ajax if this is not
possible.  Setting the widget to invisible or disabled before setValue() had
no effect on the Ajax handling.

 

If you have the time to take a look, the code below works without Ajax,
making sure the unselected row widgets are set to false.  

 

<fd:booleanfield id="archiveVersionSelect">

    <fd:on-value-changed>

        <fd:javascript>

            var source = event.getSourceWidget();

            var row = source.getParent();

            var rownum = row.getName();

            cocoon.log.warn("source row: " + rownum + " value: " +
source.getValue());

            if (source.getValue() == 'true') {

                var repeater = row.getParent();

                for (var i = 0; i &lt; repeater.getSize(); i++){

                    if (i != rownum) {

                        if
(repeater.getRow(i).getChild("archiveVersionSelect").getValue() == 'true') {

                            cocoon.log.warn("row set to false: " + i);

 
repeater.getRow(i).getChild("archiveVersionSelect").setValue(false)

                        }

                    }

                }

            }

        </fd:javascript>

     </fd:on-value-changed>

</fd:booleanfield>

 

Here's the log (without Ajax) where initially row 0 is true and row 1 is
clicked:

 

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row: 1
value: true

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - row set to
false: 0

WARN  [http-8080-Processor25] flow 2007-10-23 16:11:24,863 - source row: 0
value: false

 

This is the log with Ajax:

 

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row: 1
value: true

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - row set to
false: 0

WARN  [http-8080-Processor23] flow 2007-10-23 16:10:04,581 - source row: 0
value: false

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row: 0
value: true

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - row set to
false: 1

WARN  [http-8080-Processor24] flow 2007-10-23 16:10:04,753 - source row: 1
value: false

 

Even though the log says rows 0 and 1 are set to false they are still
checked on the screen.  

 

Thanks,

gary

 

  _____  

From: Robin Wyles [mailto:rob@robinwyles.com] 
Sent: Tuesday, October 23, 2007 10:43 AM
To: users@cocoon.apache.org
Subject: Re: CForms repeater with Ajax problem

 

Gary, me again!

 

Quick thought - have you tried setting the state of the repeater to
invisible at the start of your action triggered by the on-change event, and
then back to active again at the end? I've often found this to sort out ajax
updates in a repeater where you are updating widgets in different rows.

 

If this doesn't help maybe you could post the relevant parts of your form
definition and template and the action code too.

 

Robin

 

On 23 Oct 2007, at 15:10, Gary Larsen wrote:





I'm using Cocoon 2.1.9.  I have a repeater grid where each row contains a
booleanfield to select a row.

 

My problem is I only want one row selected at a time.  Without Ajax the
on-change event I created will successfully toggle off other rows when one
is selected.  With Ajax turned on it seems like there is a cascade effect
going on, the result is the other rows are not being turned off.

 

Perhaps there is another way to implement a grid like this which will work
with Ajax?

 

Thanks for any suggestions.

gary





 


Re: CForms repeater with Ajax problem

Posted by Robin Wyles <ro...@robinwyles.com>.
Gary, me again!

Quick thought - have you tried setting the state of the repeater to  
invisible at the start of your action triggered by the on-change  
event, and then back to active again at the end? I've often found  
this to sort out ajax updates in a repeater where you are updating  
widgets in different rows.

If this doesn't help maybe you could post the relevant parts of your  
form definition and template and the action code too.

Robin

On 23 Oct 2007, at 15:10, Gary Larsen wrote:

> I’m using Cocoon 2.1.9.  I have a repeater grid where each row  
> contains a booleanfield to select a row.
>
>
>
> My problem is I only want one row selected at a time.  Without Ajax  
> the on-change event I created will successfully toggle off other  
> rows when one is selected.  With Ajax turned on it seems like there  
> is a cascade effect going on, the result is the other rows are not  
> being turned off.
>
>
>
> Perhaps there is another way to implement a grid like this which  
> will work with Ajax?
>
>
>
> Thanks for any suggestions.
>
> gary
>
>