You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by beyaNet <an...@jibeya.com> on 2004/11/06 12:58:51 UTC

iteration problem with flow

Hi,
I have an html form which has a number of checkboxes which when 
selected indicate that the item should be deleted from an order. All 
the checkboxes share the same name, delItem. So when the form is 
submitted and depending on the number of items I have selected to be 
deleted, what gets posted in the form should be an array of delItems:

[val1, val2, val3]

So, in my flowscript which checks this value i do:

var items = cocoon.request.get("delItem");

var iterator = items.iterator();

I then get an error message saying that iterator is not a function. 
What am I doing wrong here?

many thanks

Andrew


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: iteration problem with flow

Posted by beyaNet <an...@jibeya.com>.
Johannes,
thanks for your help. Works a treat ;-)

regards

Andrew


On 6 Nov 2004, at 12:28, Johannes Textor wrote:

> var items = new java.util.Vector();
>
> if(cocoon.request.get("delItem"))
>    if(cocoon.request.get("delItem").iterator) // no brackets, this 
> just checks if it has an iterator at all
>       items.addAll(cocoon.request.get("delItem"));
>    else
>       items.add(cocoon.request.get("delItem"));


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: iteration problem with flow

Posted by Johannes Textor <jc...@gmx.de>.
Hi Andrew,

not sure about this but cocoon behaves the following way for multiple 
checkboxes:

- if no checkbox is selected, you get no value, i.e. 
cocoon.request.get("delItem") is null.
- if one checkbox is selected, you get a simple value, i.e. 
cocoon.request.get("delItem") is  for example "5".
- if two or more checkboxes are selected, you get an instance of 
java.util.List

Only in the latter case you can use the iterator function. In the first 
two cases, items.iterator() will
be undefined. So you should actually do some pre-processing like this to 
have a list in any case:

var items = new java.util.Vector();

if(cocoon.request.get("delItem"))
    if(cocoon.request.get("delItem").iterator) // no brackets, this just 
checks if it has an iterator at all
       items.addAll(cocoon.request.get("delItem"));
    else
       items.add(cocoon.request.get("delItem"));

This is a little nasty sometimes, but I guess it can't be implemented 
differently in cocoon.

HTH,
Johannes


beyaNet wrote:

> Hi,
> I have an html form which has a number of checkboxes which when 
> selected indicate that the item should be deleted from an order. All 
> the checkboxes share the same name, delItem. So when the form is 
> submitted and depending on the number of items I have selected to be 
> deleted, what gets posted in the form should be an array of delItems:
>
> [val1, val2, val3]
>
> So, in my flowscript which checks this value i do:
>
> var items = cocoon.request.get("delItem");
>
> var iterator = items.iterator();
>
> I then get an error message saying that iterator is not a function. 
> What am I doing wrong here?
>
> many thanks
>
> Andrew
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org