You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Andrew <an...@gmail.com> on 2006/07/22 16:24:36 UTC

checkbox widget with datatype vector

Hi,
I have a shopping cart system which enables a user to select a number of
items from their cart and delete them at the same time. This was working
perfectly before I chnaged everything to widgets because I need to use ajax.
What is happening now is that no matter how many items you select to delete,
only one item is ever deleted at a time. Now I suspect that the problem lays
with the datatype being used in fd:

    <fd:field id="delItem" required="true|false">
      <fd:datatype base="string"/> // I tried boolean and nothing was being
deleted
    </fd:field>

widget definition is:

     <ft:widget id= "delItem">
        <fi:styling value="${orderitem.getID()}" type="checkbox"/>
     </ft:widget>

flow:

        delItems = bizData.delItem;
        var items = new java.util.Vector();

        if (parseInt(bizData.quantity) || delItems != null) {
            try {

                if (delItems != null) {

                   if (delItems.iterator) { // A list of delItems have been
selected to be deleted.
                      items.addAll(delItems);
                      deleteOrderItem2(items);
                   } else { //A single delItem has been selected to be
deleted.
                      items.add(delItems);
                      deleteOrderItem2(items);
                   }
                }

Any ideas what I am missing here?

regards

Andrew

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,
on further investigation I see that I have made a mistake. The  previous
code snippet should have read:

if(java.lang.Boolean.TRUE.equals(row.lookupWidget("delete").value)) {
  itemsToDelete.add(row.lookupWidget("id").value); //add item to delete
  deleteOrderItem2(itemsToDelete);

  //now delete item row from repeater

}

Once I have the itemID I add it to the vector and send that to my delete
orderItem function. What I then want to do is to delete the actual row from
the table associaated with the orderItem ID. How do I do that in flow? I
also have a snippet which handles adding orderItems:

                if (parseInt(bizData.quantity)) { //Add a row if need be
                    //add a row and an item to the orderitem
                    addOrderItem(bizData.quantity, bizData.orderID,
bizData.stockID);

                    //Now add this item to the repeater
               }

and again, once the orderitem object has been updated I now want to add that
item to the repeater. I tried:

                   //Now add this item to the repeater
                   form.lookupWidget ('items')
                   .addRow()
                   .getChild('id').value = orderitem.getID()
                   .getChild('artistName').value = orderitem.getArtistName()
                   .getChild('itemTitle').value = orderitem.getStock
().getItemTitle()
                   .getChild('amount').value = orderitem.getAmount()
                   .getChild('price').value = orderitem.getPrice()

but get an 'TypeError: getChild is not a function.'

So how do I do also add a row item to a repeater from within flow?

regards

Andrew

On 25/07/06, Andrew <an...@gmail.com> wrote:
>
> Hi Jason,
> first off I have to say I appreciate the time you put into helping me
> grasp these concepts, much appreciated.
>
> Ok, so I have in jx file:
>
>                       <ft:repeater-rows>
>
>                       <tr>
>                         <td width="8" class="normaltext"></td>
>                         <td class="normaltext"><ft:widget id="id" /></td>
>
>                         <td width="8" class="normaltext"></td>
>                         <td class="normaltext"><ft:widget id="artistName"
> /></td>
>
>                         <td width="8" class="normaltext"></td>
>                         <td class="normaltext"><ft:widget id="itemTitle"
> /></td>
>                         <td class="normaltext"></td>
>                         <td class="normaltext"><ft:widget id="amount"
> /></td>
>                         <td class="normaltext"></td>
>                         <td class="normaltext"><ft:widget id="price"
> />.00</td>
>                         <td class="normaltext"></td>
>                         <td class="normaltext"><ft:widget id="delete"
> /></td>
>                       </tr>
>                       </ft:repeater-rows>
>
> and in my validation:
>
>     <fd:repeater id="items" initial-size="0">
>
>           <fd:widgets>
>             <fd:output id="id">
>                   <fd:datatype base="string" />
>
>             </fd:output>
>             <fd:output id="artistName">
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:output id="itemTitle">
>
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:output id="amount">
>
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:output id="price">
>
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:booleanfield id="delete" />
>           </fd:widgets>
>     </fd:repeater>
>
> and in my flow:
>
>                 if (repeaterSize != 0) { //Delete a row if need be
>                     //delete a row and an item from the orderitem
>
>                     for(var i=0; i < repeater.getSize(); i++) { //loop
> over the rows
>                       var row = repeater.getRow(i);
>                       if(java.lang.Boolean.TRUE.equals(row.lookupWidget("delete").value)) { //is the booleanfield checked?
>                         itemsToDelete.add(row.lookupWidget("id").value);
> //add the item id to delete from widget
>
>                         //now delete item from orderitems object
>                         items.add(row.lookupWidget("id").value);
>                         deleteOrderItem2(items);
>                       }
>                     }
>
>                 }
>
>                 if (parseInt(bizData.quantity)) { //Add a row if need be
>                     //add a row and an item to the orderitem
>                     addOrderItem(bizData.quantity, bizData.orderID ,
> bizData.stockID);
>
>                    // add values to repeater widgets, and then add row to
> repeater-rows
>                 }
>
> So how in flow do I add values to each of the widgets, (id, artistName,
> etc etc etc), in the repeater, and then add that row to <ft:repeater-rows>?
>
> regards
>
> Andrew
>
>
> On 25/07/06, Jason Johnston <co...@lojjic.net> wrote:
> >
> > Jason Johnston wrote:
> > > var itemsToDelete = new java.util.Vector();
> > > var repeater = form.lookupWidget("items");
> > > for(var i=0; i<repeater.getSize(); i++) { //loop over the rows
> > >   var row = repeater.getRow(i);
> > >   if(row.lookupWidget("delete").value) { //is the booleanfield
> > checked?
> >
> > Small correction... the above line should probably be something more
> > like:
> >
> > if(java.lang.Boolean.TRUE.equals (row.lookupWidget("delete").value)) {
> >
> > Datatype conversion between Java and JS can be tricky at times. ;-)
> >
> >
> > >     itemsToDelete.add(row.lookupWidget("id").value); //add the item id
> > >   }
> > > }
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
>

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,
all is working now! I forgot to specify form.load(bean) before the
form.showform!!

Many many thanks for your patience and help

regards

Andrew

On 25/07/06, Andrew <an...@gmail.com> wrote:
>
> Hi Jason,
> we're nearly there! I've created the binding document, implemented it into
> flow but no rows are being displayed when I update the order object!! What
> am I overlooking?
>
> flow:
>
> var form = new Form("forms/artistOrder_new.xml");
> form.createBinding("binding/artistOrder_binding.xml");
> form.showForm("viewform-artistOrder_new.xml",{"artistID":artistID,"artist_name":artist_name,"artist_info":artist_info,"track_info":track_info,"track_location":track_location,"track_type":track_type,"stock_code":stock_code,"userGlobal":userGlobal,"neworder":neworder,"stock_price":stock_price,"msg":delItems,"msg2":msg2,
> "track_title":track_title});
> ...........
>
>         if (parseInt(bizData.quantity) || repeaterSize != 0) {
>             try {
>
>
>                 if (repeaterSize != 0) { //Delete a row if need be
>                     //delete a row and an item from the orderitem
>                     for(var i=0; i < repeater.getSize(); i++) { //loop
> over the rows
>                       var row = repeater.getRow(i);
>                       if(java.lang.Boolean.TRUE.equals(row.lookupWidget("delete").value)) { //is the booleanfield checked?
>                         itemsToDelete.add(row.lookupWidget("id").value);
> //add the item id to delete from widget
>                         deleteOrderItem2(itemsToDelete);
>
>                         //now delete item row from repeater
>                         form.load(neworder);
>
>                       }
>                     }
>
>                 }
>
>                 if (parseInt(bizData.quantity)) { //Add a row if need be
>                     //add a row and an item to the orderitem
>                     addOrderItem(bizData.quantity, bizData.orderID ,
> bizData.stockID);
>
>                     //Now add this item to the repeater
>                     form.load(neworder);
>
> binding:
>
> <?xml version="1.0"?>
> <fb:context xmlns:fb=" http://apache.org/cocoon/forms/1.0#binding"
>             path="/">
>
> <fb:simple-repeater id="items" parent-path="."
> row-path="neworder/orderItems" direction="load">
>
>   <fb:value id="id" path="ID" />
>   <fb:value id="artistName" path="artistName" />
>   <fb:value id="itemTitle" path="Stock/ItemTitle" />
>   <fb:value id="amount" path="Amount />
>   <fb:value id="price" path="Price" />
> </fb:simple-repeater>
>
> </fb:context>
>
>
> jx file:
>
>                               <ft:repeater-rows>
>                               <tr>
>                                 <td width="8" class="normaltext"></td>
>                                 <td class="normaltext"><ft:widget id="id"
> /></td>
>                                 <td width="8" class="normaltext"></td>
>                                 <td class="normaltext"><ft:widget
> id="artistName" /></td>
>                                 <td width="8" class="normaltext"></td>
>                                 <td class="normaltext"><ft:widget
> id="itemTitle" /></td>
>                                 <td class="normaltext"></td>
>                                 <td class="normaltext"><ft:widget
> id="amount" /></td>
>                                 <td class="normaltext"></td>
>                                 <td class="normaltext"><ft:widget
> id="price" />.00</td>
>                                 <td class="normaltext"></td>
>                                 <td class="normaltext"><ft:widget
> id="delete" /></td>
>                               </tr>
>                               </ft:repeater-rows>
>
> fd:validation:
>
>
>     <fd:repeater id="items" initial-size="0">
>           <fd:widgets>
>             <fd:output id="id">
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:output id="artistName">
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:output id="itemTitle">
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:output id="amount">
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:output id="price">
>                   <fd:datatype base="string" />
>             </fd:output>
>             <fd:booleanfield id="delete" />
>           </fd:widgets>
>     </fd:repeater>
>
> regards
>
> Andrew
>
>
>
>
>
> On 25/07/06, Jason Johnston <co...@lojjic.net> wrote:
>
> > Andrew wrote:
> > > Hi Jason,
> > > first off I have to say I appreciate the time you put into helping me
> > > grasp these concepts, much appreciated.
> > >
> >
> > No problem.
> >
> > >
> > > So how in flow do I add values to each of the widgets, (id,
> > artistName,
> > > etc etc etc), in the repeater, and then add that row to
> > <ft:repeater-rows>?
> >
> > Like I mentioned before, I think the easiest way to load data into the
> > repeater is with a fb:simple-repeater binding.  I presume you're not
> > familiar with the binding framework; it's basically a way to define (in
> > an XML syntax) how to map values between a business object and the form
> > object's widgets.  See the documentation:
> > http://cocoon.apache.org/2.1/userdocs/binding.html
> >
> > There's a special binding type called fb:simple-repeater (named such
> > since it's much simpler than the full fb:repeater binding, but should be
> > sufficient for your case) that lets you bind values from a Collection,
> > Array, or anything else that JXPath can iterate over, to and from a
> > fd:repeater widget and all its children.  Something like:
> >
> > In a binding file:
> >
> > ...
> > <fb:simple-repeater id="items" parent-path="." row-path="orderItems"
> >                      direction="load">
> >    <fb:value id="id" path="ID" />
> >    <fb:value id="artistName" path="..." />
> >    ...
> > </fb:simple-repeater>
> > ...
> >
> > In your flow:
> >
> > form.createBinding("path/to/binding-file.xml"); //creates the binding
> > ...
> > form.load(neworder); //loads the data into the form using the binding
> >
> > That's it.  You can call form.load() as many times in your flow as you
> > want, such as after you delete items or a new item is added.  As long as
> > the orderItems list contains the up-to-date list of items, the repeater
> > will be updated to match.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
>

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,
we're nearly there! I've created the binding document, implemented it into
flow but no rows are being displayed when I update the order object!! What
am I overlooking?

flow:

var form = new Form("forms/artistOrder_new.xml");
form.createBinding("binding/artistOrder_binding.xml");
form.showForm("viewform-artistOrder_new.xml",{"artistID":artistID,"artist_name":artist_name,"artist_info":artist_info,"track_info":track_info,"track_location":track_location,"track_type":track_type,"stock_code":stock_code,"userGlobal":userGlobal,"neworder":neworder,"stock_price":stock_price,"msg":delItems,"msg2":msg2,
"track_title":track_title});
...........

        if (parseInt(bizData.quantity) || repeaterSize != 0) {
            try {

                if (repeaterSize != 0) { //Delete a row if need be
                    //delete a row and an item from the orderitem
                    for(var i=0; i < repeater.getSize(); i++) { //loop over
the rows
                      var row = repeater.getRow(i);

if(java.lang.Boolean.TRUE.equals(row.lookupWidget("delete").value))
{ //is the booleanfield checked?
                        itemsToDelete.add(row.lookupWidget("id").value);
//add the item id to delete from widget
                        deleteOrderItem2(itemsToDelete);

                        //now delete item row from repeater
                        form.load(neworder);
                      }
                    }

                }

                if (parseInt(bizData.quantity)) { //Add a row if need be
                    //add a row and an item to the orderitem
                    addOrderItem(bizData.quantity, bizData.orderID,
bizData.stockID);

                    //Now add this item to the repeater
                    form.load(neworder);

binding:

<?xml version="1.0"?>
<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"
            path="/">

<fb:simple-repeater id="items" parent-path="."
row-path="neworder/orderItems" direction="load">
  <fb:value id="id" path="ID" />
  <fb:value id="artistName" path="artistName" />
  <fb:value id="itemTitle" path="Stock/ItemTitle" />
  <fb:value id="amount" path="Amount />
  <fb:value id="price" path="Price" />
</fb:simple-repeater>

</fb:context>

jx file:

                              <ft:repeater-rows>
                              <tr>
                                <td width="8" class="normaltext"></td>
                                <td class="normaltext"><ft:widget id="id"
/></td>
                                <td width="8" class="normaltext"></td>
                                <td class="normaltext"><ft:widget
id="artistName" /></td>
                                <td width="8" class="normaltext"></td>
                                <td class="normaltext"><ft:widget
id="itemTitle" /></td>
                                <td class="normaltext"></td>
                                <td class="normaltext"><ft:widget
id="amount" /></td>
                                <td class="normaltext"></td>
                                <td class="normaltext"><ft:widget id="price"
/>.00</td>
                                <td class="normaltext"></td>
                                <td class="normaltext"><ft:widget
id="delete" /></td>
                              </tr>
                              </ft:repeater-rows>

fd:validation:

    <fd:repeater id="items" initial-size="0">
          <fd:widgets>
            <fd:output id="id">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="artistName">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="itemTitle">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="amount">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="price">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:booleanfield id="delete" />
          </fd:widgets>
    </fd:repeater>

regards

Andrew





On 25/07/06, Jason Johnston <co...@lojjic.net> wrote:
>
> Andrew wrote:
> > Hi Jason,
> > first off I have to say I appreciate the time you put into helping me
> > grasp these concepts, much appreciated.
> >
>
> No problem.
>
> >
> > So how in flow do I add values to each of the widgets, (id, artistName,
> > etc etc etc), in the repeater, and then add that row to
> <ft:repeater-rows>?
>
> Like I mentioned before, I think the easiest way to load data into the
> repeater is with a fb:simple-repeater binding.  I presume you're not
> familiar with the binding framework; it's basically a way to define (in
> an XML syntax) how to map values between a business object and the form
> object's widgets.  See the documentation:
> http://cocoon.apache.org/2.1/userdocs/binding.html
>
> There's a special binding type called fb:simple-repeater (named such
> since it's much simpler than the full fb:repeater binding, but should be
> sufficient for your case) that lets you bind values from a Collection,
> Array, or anything else that JXPath can iterate over, to and from a
> fd:repeater widget and all its children.  Something like:
>
> In a binding file:
>
> ...
> <fb:simple-repeater id="items" parent-path="." row-path="orderItems"
>                      direction="load">
>    <fb:value id="id" path="ID" />
>    <fb:value id="artistName" path="..." />
>    ...
> </fb:simple-repeater>
> ...
>
> In your flow:
>
> form.createBinding("path/to/binding-file.xml"); //creates the binding
> ...
> form.load(neworder); //loads the data into the form using the binding
>
> That's it.  You can call form.load() as many times in your flow as you
> want, such as after you delete items or a new item is added.  As long as
> the orderItems list contains the up-to-date list of items, the repeater
> will be updated to match.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Andrew wrote:
> Hi Jason,
> first off I have to say I appreciate the time you put into helping me 
> grasp these concepts, much appreciated.
> 

No problem.

> 
> So how in flow do I add values to each of the widgets, (id, artistName, 
> etc etc etc), in the repeater, and then add that row to <ft:repeater-rows>?

Like I mentioned before, I think the easiest way to load data into the 
repeater is with a fb:simple-repeater binding.  I presume you're not 
familiar with the binding framework; it's basically a way to define (in 
an XML syntax) how to map values between a business object and the form 
object's widgets.  See the documentation: 
http://cocoon.apache.org/2.1/userdocs/binding.html

There's a special binding type called fb:simple-repeater (named such 
since it's much simpler than the full fb:repeater binding, but should be 
sufficient for your case) that lets you bind values from a Collection, 
Array, or anything else that JXPath can iterate over, to and from a 
fd:repeater widget and all its children.  Something like:

In a binding file:

...
<fb:simple-repeater id="items" parent-path="." row-path="orderItems"
                     direction="load">
   <fb:value id="id" path="ID" />
   <fb:value id="artistName" path="..." />
   ...
</fb:simple-repeater>
...

In your flow:

form.createBinding("path/to/binding-file.xml"); //creates the binding
...
form.load(neworder); //loads the data into the form using the binding

That's it.  You can call form.load() as many times in your flow as you 
want, such as after you delete items or a new item is added.  As long as 
the orderItems list contains the up-to-date list of items, the repeater 
will be updated to match.

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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,
first off I have to say I appreciate the time you put into helping me grasp
these concepts, much appreciated.

Ok, so I have in jx file:

                      <ft:repeater-rows>
                      <tr>
                        <td width="8" class="normaltext"></td>
                        <td class="normaltext"><ft:widget id="id" /></td>
                        <td width="8" class="normaltext"></td>
                        <td class="normaltext"><ft:widget id="artistName"
/></td>
                        <td width="8" class="normaltext"></td>
                        <td class="normaltext"><ft:widget id="itemTitle"
/></td>
                        <td class="normaltext"></td>
                        <td class="normaltext"><ft:widget id="amount"
/></td>
                        <td class="normaltext"></td>
                        <td class="normaltext"><ft:widget id="price"
/>.00</td>
                        <td class="normaltext"></td>
                        <td class="normaltext"><ft:widget id="delete"
/></td>
                      </tr>
                      </ft:repeater-rows>

and in my validation:

    <fd:repeater id="items" initial-size="0">
          <fd:widgets>
            <fd:output id="id">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="artistName">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="itemTitle">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="amount">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:output id="price">
                  <fd:datatype base="string" />
            </fd:output>
            <fd:booleanfield id="delete" />
          </fd:widgets>
    </fd:repeater>

and in my flow:

                if (repeaterSize != 0) { //Delete a row if need be
                    //delete a row and an item from the orderitem
                    for(var i=0; i < repeater.getSize(); i++) { //loop over
the rows
                      var row = repeater.getRow(i);

if(java.lang.Boolean.TRUE.equals(row.lookupWidget("delete").value))
{ //is the booleanfield checked?
                        itemsToDelete.add(row.lookupWidget("id").value);
//add the item id to delete from widget

                        //now delete item from orderitems object
                        items.add(row.lookupWidget("id").value);
                        deleteOrderItem2(items);
                      }
                    }

                }

                if (parseInt(bizData.quantity)) { //Add a row if need be
                    //add a row and an item to the orderitem
                    addOrderItem(bizData.quantity, bizData.orderID,
bizData.stockID);

                   // add values to repeater widgets, and then add row to
repeater-rows
                }

So how in flow do I add values to each of the widgets, (id, artistName, etc
etc etc), in the repeater, and then add that row to <ft:repeater-rows>?

regards

Andrew

On 25/07/06, Jason Johnston <co...@lojjic.net> wrote:
>
> Jason Johnston wrote:
> > var itemsToDelete = new java.util.Vector();
> > var repeater = form.lookupWidget("items");
> > for(var i=0; i<repeater.getSize(); i++) { //loop over the rows
> >   var row = repeater.getRow(i);
> >   if(row.lookupWidget("delete").value) { //is the booleanfield checked?
>
> Small correction... the above line should probably be something more like:
>
> if(java.lang.Boolean.TRUE.equals(row.lookupWidget("delete").value)) {
>
> Datatype conversion between Java and JS can be tricky at times. ;-)
>
>
> >     itemsToDelete.add(row.lookupWidget("id").value); //add the item id
> >   }
> > }
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Jason Johnston wrote:
> var itemsToDelete = new java.util.Vector();
> var repeater = form.lookupWidget("items");
> for(var i=0; i<repeater.getSize(); i++) { //loop over the rows
>   var row = repeater.getRow(i);
>   if(row.lookupWidget("delete").value) { //is the booleanfield checked?

Small correction... the above line should probably be something more like:

if(java.lang.Boolean.TRUE.equals(row.lookupWidget("delete").value)) {

Datatype conversion between Java and JS can be tricky at times. ;-)


>     itemsToDelete.add(row.lookupWidget("id").value); //add the item id
>   }
> }
> 

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


Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Andrew wrote:
> Hi Jason,
> 
>     3) Use a repeater rather than the JX loop.  It sounds like you were
>     trying to enable AJAX for this form, so this may be your best bet.
>     Either of the first two choices above would be difficult to make work
>     with CForms' AJAX framework.  Personally I think this is the cleanest
>     approach. 
> 
> 
> Ok. So the first issue to address is how to tell the repeater to repeat 
> only as many times as there are items in the orderItem object? 

When you load data into the repeater (a fb:simple-repeater binding is 
probably the easiest way) it automatically works that way; it displays 
the rows it contains and nothing more.

> Secondly, 
> let's say that I have 2 orderItems which read by the repeater will give 
> me 2 rows. So each row will comprise a check box called delItem (which 
> when selected enables that row to be deleted), this brings us right back 
> to the problem we had at the begining, what datatype to give delItem so 
> that in flow delItem is recognised as a vector, which it would be if I 
> were to defined using a conventional, non widget, <input type="checkbox 
> /> html approach? I have an fd:datatype for delItem as string at the 
> moment:
> 
>     <fd:field id="delItem">
>       <fd:datatype base="string"/>
>     </fd:field>
> 
>      <ft:widget id= "delItem">
>        <fi:styling value="${ orderitem.getID()}" type="checkbox"/>
>      </ft:widget>
> 
> and no matter how many delItems you select, only one is ever deleted at 
> a time! Is there no way to introduce datatypes, for example 
> java.Util.Vector !?! This would resolve the problem I am having without 
> the need for repeaters or multivaluefields.

I think you're really mixing concepts up.  You're wanting to put 
multiple values into a widget (fd:field) that *by definition* has a 
single value.  There's a special kind of field designed specifically for 
holding multiple values: *multivaluefield*!  So if you want one value 
use fd:field, if you want multiple use fd:multivaluefield, it's that simple.

So anyway, let's get back to repeaters and try to switch your thinking a 
little bit...

Rather than having a single widget with multiple values, you will have 
multiple repeater rows each with a fd:booleanfield widget which acts as 
a flag that the item represented by that row should be deleted:

<fd:repeater id="items">
   <fd:widgets>
     <fd:output id="id">
       <fd:datatype base="integer" />
     </fd:output>
     <fd:output id="artistName">
       <fd:datatype base="string" />
     </fd:output>
     ...
     <fd:booleanfield id="delete" />
   </fd:widgets>
</fd:repeater>

Then afterward in your flow, you can just iterate over all of the 
repeater's rows, see which ones have their booleanfield checked, and 
build your Vector/Collection from them.  Something like:

var itemsToDelete = new java.util.Vector();
var repeater = form.lookupWidget("items");
for(var i=0; i<repeater.getSize(); i++) { //loop over the rows
   var row = repeater.getRow(i);
   if(row.lookupWidget("delete").value) { //is the booleanfield checked?
     itemsToDelete.add(row.lookupWidget("id").value); //add the item id
   }
}

Besides the template, which is straightforward, that should be it.



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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,

3) Use a repeater rather than the JX loop.  It sounds like you were
> trying to enable AJAX for this form, so this may be your best bet.
> Either of the first two choices above would be difficult to make work
> with CForms' AJAX framework.  Personally I think this is the cleanest
> approach.


Ok. So the first issue to address is how to tell the repeater to repeat only
as many times as there are items in the orderItem object? Secondly, let's
say that I have 2 orderItems which read by the repeater will give me 2 rows.
So each row will comprise a check box called delItem (which when selected
enables that row to be deleted), this brings us right back to the problem we
had at the begining, what datatype to give delItem so that in flow delItem
is recognised as a vector, which it would be if I were to defined using a
conventional, non widget, <input type="checkbox /> html approach? I have an
fd:datatype for delItem as string at the moment:

    <fd:field id="delItem">
      <fd:datatype base="string"/>
    </fd:field>

     <ft:widget id= "delItem">
       <fi:styling value="${orderitem.getID()}" type="checkbox"/>
     </ft:widget>

and no matter how many delItems you select, only one is ever deleted at a
time! Is there no way to introduce datatypes, for example
java.Util.Vector!?! This would resolve the problem I am having without
the need for
repeaters or multivaluefields.

You may find this post interesting:

http://marc2.theaimsgroup.com/?l=xml-cocoon-dev&m=112360780807093&w=2

regards

Andrew

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Andrew wrote:
> Hi,
> all is working now, but.......
> 
> Ok, so I have a jx loop which pulls in all of the orderitem details 
> required to be displayed to a user:
> 
> <jx:forEach var="orderitem" items="${neworder.getOrderItems ()}">
>                       <tr>
>                         <td width="8" class="normaltext"></td>
>                         <td class="normaltext">${orderitem.getID ()}</td>
>                         <td width="8" class="normaltext"></td>
>                         <td 
> class="normaltext">${orderitem.getArtistName()}</td>
>                         <td width="8" class="normaltext"></td>
>                         <td 
> class="normaltext">${orderitem.getStock().getItemTitle()}</td>
>                         <td class="normaltext"></td>
>                         <td 
> class="normaltext">${orderitem.getAmount()}</td> 
>                         <td class="normaltext"></td>
>                         <td class="normaltext">${ 
> orderitem.getPrice()}.00</td>
>                         <td class="normaltext"></td>
>                         <td class="normaltext">
>                         <ft:widget id= "delItem">
>                             <fi:styling list-type="checkbox"/> 
> //MultiValueField
>                         </ft:widget>
>                         </td>               
>                       </tr>
>                       </jx:forEach>


Ah, now I see.  If I'd known this was what you were going for I wouldn't 
have recommended the selection-list approach.

I think you have a few choices:

1) Create your own custom styling for fi:multivaluefield that displays 
only a single checkbox where you set its value, sort of like you were 
doing before.

2) Bypass the ft:widget call altogether and just write out your own 
<input type="checkbox" name="delItem" value="${...}" /> for each row.

3) Use a repeater rather than the JX loop.  It sounds like you were 
trying to enable AJAX for this form, so this may be your best bet. 
Either of the first two choices above would be difficult to make work 
with CForms' AJAX framework.  Personally I think this is the cleanest 
approach.

> 
> <fd:multivaluefield id="delItem">
>       <fd:datatype base="string"/>
>       <fd:selection-list nullable="false" type="flow-jxpath" 
> list-path="neworder/orderItems" value-path="ID" label-path="''" />
>     </fd:multivaluefield>
> 
> Having the delItem widget in the table now means that for every item in 
> the users cart, 1 extra checkbox will be displayed for that orderitem, 
> because I basically have a loop within a loop! So basically what I need 
> is a widget that will allow me to create a table like the one above, 
> minus the final mulivaluefield widget, pulling in all orderitems from 
> one source instead of two sources like above. Is this possible?
> 
> The solution I had before using jx to iterate through an object does not 
> work as there is no fd:validation which can handle a number of fields 
> with the same id that is not generated by a multivaluefield. Also the 
> multvaluefield option does not work as it will give me a list of 
> checkboxes based on the number of items within an object. There is then 
> no way to marry the checkboxes with other items, as I have, displayed by 
> a jx loop which itself iterates through the same object as the 
> multivaluefield. Any solution here at all?

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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi,
all is working now, but.......

Ok, so I have a jx loop which pulls in all of the orderitem details required
to be displayed to a user:

<jx:forEach var="orderitem" items="${neworder.getOrderItems()}">
                      <tr>
                        <td width="8" class="normaltext"></td>
                        <td class="normaltext">${orderitem.getID()}</td>
                        <td width="8" class="normaltext"></td>
                        <td class="normaltext">${orderitem.getArtistName
()}</td>
                        <td width="8" class="normaltext"></td>
                        <td
class="normaltext">${orderitem.getStock().getItemTitle()}</td>

                        <td class="normaltext"></td>
                        <td class="normaltext">${orderitem.getAmount()}</td>

                        <td class="normaltext"></td>
                        <td class="normaltext">${orderitem.getPrice()}.00</td>

                        <td class="normaltext"></td>
                        <td class="normaltext">
                        <ft:widget id= "delItem">
                            <fi:styling list-type="checkbox"/>
//MultiValueField
                        </ft:widget>
                        </td>
                      </tr>
                      </jx:forEach>

<fd:multivaluefield id="delItem">
      <fd:datatype base="string"/>
      <fd:selection-list nullable="false" type="flow-jxpath"
list-path="neworder/orderItems" value-path="ID" label-path="''" />
    </fd:multivaluefield>

Having the delItem widget in the table now means that for every item in the
users cart, 1 extra checkbox will be displayed for that orderitem, because I
basically have a loop within a loop! So basically what I need is a widget
that will allow me to create a table like the one above, minus the final
mulivaluefield widget, pulling in all orderitems from one source instead of
two sources like above. Is this possible?

The solution I had before using jx to iterate through an object does not
work as there is no fd:validation which can handle a number of fields with
the same id that is not generated by a multivaluefield. Also the
multvaluefield option does not work as it will give me a list of checkboxes
based on the number of items within an object. There is then no way to marry
the checkboxes with other items, as I have, displayed by a jx loop which
itself iterates through the same object as the multivaluefield. Any solution
here at all?

regards

Andrew

On 24/07/06, Andrew <an...@gmail.com> wrote:
>
> Ok,
> what I needed was:
>
> form.lookupWidget("widgetid").value
>
> So what gives with var model = form.getModel()? Does getModel not pick up
> all the widgets, and model.widgetid not simply pull the value out of the
> widget?
>
>
> regards
>
> Andrew
>
> On 24/07/06, Andrew <an...@gmail.com> wrote:
> >
> > Hi,
> >
> >
> >         var model = form.getModel();
> >         var bizData = {"next" : model.next, "delItem" : model.delItem,
> > "quantity" : model.quantity, "orderID" : model.orderID, "stockID" :
> > model.stockID}
> >         var confirmOrder = bizData.next;
> >         var delItems2 = bizData.delItem; //The list of selected
> > checkboxes
> >         var delItems = java.util.Arrays.asList(delItems2);
> >
> > The above gives me the follwoing error:
> >
> > Cannot convert
> > org.apache.cocoon.forms.flow.javascript.ScriptableWidget@b4216d to
> > java.lang.Object[]
> >
> > So when I do:
> >
> > var delItems = java.util.Arrays.asList(delItems2.getValue ());
> >
> > I get the follwoing error message:
> >
> > getValue is not a function.
> >
> > What am I missing here?
> >
> > regards
> >
> > Andrew
> >
> >
> >
> > On 24/07/06, Andrew <an...@gmail.com> wrote:
> > >
> > > Hi Jason,
> > > my bad! bizdata is represented as follows in flow:
> > >
> > >         var model = form.getModel();
> > >         var bizData = {"next" : model.next, "delItem" : model.delItem,
> > > "quantity" : model.quantity, "orderID" : model.orderID, "stockID" :
> > > model.stockID}
> > >         var confirmOrder = bizData.next;
> > >
> > >         delItems = bizData.delItem;
> > >         var items = new java.util.Vector();
> > >
> > >         if (parseInt(bizData.quantity) || delItems != null) {
> > >             try {
> > >
> > >                 if (delItems != null) {
> > >
> > >                    if ( delItems.iterator) {
> > >                       items.addAll(delItems);
> > >                       deleteOrderItem2(items);
> > >                    } else {
> > >                       items.add(delItems);
> > >                       deleteOrderItem2(items);
> > >                    }
> > >                 }
> > >
> > > HTH
> > >
> > > regards
> > >
> > > Andrew
> > >
> > >
> > > On 23/07/06, Jason Johnston < cocoon@lojjic.net> wrote:
> > > >
> > > > >      >
> > > > >      > Again the flow code is unchanged:
> > > > >      >
> > > > >      >         delItems = bizData.delItem ;
> > > > >      >         var items = new java.util.Vector();
> > > > >
> > > > >
> > > > > As delItems is now actually a widget, why can I not do this to
> > > > extract
> > > > > the value of the widget?:
> > > > >
> > > > > delItems = bizData.delItem.value;
> > > > >
> > > >
> > > > Sorry, I'm working with an incomplete picture here... I don't know
> > > > what
> > > > bizData is or what bizData.delItem returns.  If it's the actual
> > > > widget
> > > > then yes, you should be able to do .value to get its value.  That
> > > > value
> > > > will be a Java String[] array, so if you have to get that into a
> > > > Vector
> > > > or Collection to satisfy whatever API you're passing it to then
> > > > you'll
> > > > need a conversion something like what I wrote in my previous reply.
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > > For additional commands, e-mail: users-help@cocoon.apache.org
> > > >
> > > >
> > >
> >
>

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Ok,
what I needed was:

form.lookupWidget("widgetid").value

So what gives with var model = form.getModel()? Does getModel not pick up
all the widgets, and model.widgetid not simply pull the value out of the
widget?

regards

Andrew

On 24/07/06, Andrew <an...@gmail.com> wrote:
>
> Hi,
>
>
>         var model = form.getModel();
>         var bizData = {"next" : model.next, "delItem" : model.delItem,
> "quantity" : model.quantity, "orderID" : model.orderID, "stockID" :
> model.stockID}
>         var confirmOrder = bizData.next;
>         var delItems2 = bizData.delItem; //The list of selected checkboxes
>         var delItems = java.util.Arrays.asList(delItems2);
>
> The above gives me the follwoing error:
>
> Cannot convert
> org.apache.cocoon.forms.flow.javascript.ScriptableWidget@b4216d to
> java.lang.Object[]
>
> So when I do:
>
> var delItems = java.util.Arrays.asList(delItems2.getValue ());
>
> I get the follwoing error message:
>
> getValue is not a function.
>
> What am I missing here?
>
> regards
>
> Andrew
>
>
>
> On 24/07/06, Andrew <an...@gmail.com> wrote:
> >
> > Hi Jason,
> > my bad! bizdata is represented as follows in flow:
> >
> >         var model = form.getModel();
> >         var bizData = {"next" : model.next, "delItem" : model.delItem,
> > "quantity" : model.quantity, "orderID" : model.orderID, "stockID" :
> > model.stockID}
> >         var confirmOrder = bizData.next;
> >
> >         delItems = bizData.delItem;
> >         var items = new java.util.Vector();
> >
> >         if (parseInt(bizData.quantity) || delItems != null) {
> >             try {
> >
> >                 if (delItems != null) {
> >
> >                    if ( delItems.iterator) {
> >                       items.addAll(delItems);
> >                       deleteOrderItem2(items);
> >                    } else {
> >                       items.add(delItems);
> >                       deleteOrderItem2(items);
> >                    }
> >                 }
> >
> > HTH
> >
> > regards
> >
> > Andrew
> >
> >
> > On 23/07/06, Jason Johnston < cocoon@lojjic.net> wrote:
> > >
> > > >      >
> > > >      > Again the flow code is unchanged:
> > > >      >
> > > >      >         delItems = bizData.delItem ;
> > > >      >         var items = new java.util.Vector();
> > > >
> > > >
> > > > As delItems is now actually a widget, why can I not do this to
> > > extract
> > > > the value of the widget?:
> > > >
> > > > delItems = bizData.delItem.value;
> > > >
> > >
> > > Sorry, I'm working with an incomplete picture here... I don't know
> > > what
> > > bizData is or what bizData.delItem returns.  If it's the actual widget
> > >
> > > then yes, you should be able to do .value to get its value.  That
> > > value
> > > will be a Java String[] array, so if you have to get that into a
> > > Vector
> > > or Collection to satisfy whatever API you're passing it to then you'll
> > >
> > > need a conversion something like what I wrote in my previous reply.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > For additional commands, e-mail: users-help@cocoon.apache.org
> > >
> > >
> >
>

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi,

        var model = form.getModel();
        var bizData = {"next" : model.next, "delItem" : model.delItem,
"quantity" : model.quantity, "orderID" : model.orderID, "stockID" :
model.stockID}
        var confirmOrder = bizData.next;
        var delItems2 = bizData.delItem; //The list of selected checkboxes
        var delItems = java.util.Arrays.asList(delItems2);

The above gives me the follwoing error:

Cannot convert
org.apache.cocoon.forms.flow.javascript.ScriptableWidget@b4216d to
java.lang.Object[]

So when I do:

var delItems = java.util.Arrays.asList(delItems2.getValue());

I get the follwoing error message:

getValue is not a function.

What am I missing here?

regards

Andrew


On 24/07/06, Andrew <an...@gmail.com> wrote:
>
> Hi Jason,
> my bad! bizdata is represented as follows in flow:
>
>         var model = form.getModel();
>         var bizData = {"next" : model.next, "delItem" : model.delItem,
> "quantity" : model.quantity, "orderID" : model.orderID, "stockID" :
> model.stockID}
>         var confirmOrder = bizData.next;
>
>         delItems = bizData.delItem;
>         var items = new java.util.Vector();
>
>         if (parseInt(bizData.quantity) || delItems != null) {
>             try {
>
>                 if (delItems != null) {
>
>                    if (delItems.iterator) {
>                       items.addAll(delItems);
>                       deleteOrderItem2(items);
>                    } else {
>                       items.add(delItems);
>                       deleteOrderItem2(items);
>                    }
>                 }
>
> HTH
>
> regards
>
> Andrew
>
>
> On 23/07/06, Jason Johnston < cocoon@lojjic.net> wrote:
> >
> > >      >
> > >      > Again the flow code is unchanged:
> > >      >
> > >      >         delItems = bizData.delItem ;
> > >      >         var items = new java.util.Vector();
> > >
> > >
> > > As delItems is now actually a widget, why can I not do this to extract
> >
> > > the value of the widget?:
> > >
> > > delItems = bizData.delItem.value;
> > >
> >
> > Sorry, I'm working with an incomplete picture here... I don't know what
> > bizData is or what bizData.delItem returns.  If it's the actual widget
> > then yes, you should be able to do .value to get its value.  That value
> > will be a Java String[] array, so if you have to get that into a Vector
> > or Collection to satisfy whatever API you're passing it to then you'll
> > need a conversion something like what I wrote in my previous reply.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
>

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,
my bad! bizdata is represented as follows in flow:

        var model = form.getModel();
        var bizData = {"next" : model.next, "delItem" : model.delItem,
"quantity" : model.quantity, "orderID" : model.orderID, "stockID" :
model.stockID}
        var confirmOrder = bizData.next;
        delItems = bizData.delItem;
        var items = new java.util.Vector();

        if (parseInt(bizData.quantity) || delItems != null) {
            try {

                if (delItems != null) {

                   if (delItems.iterator) {
                      items.addAll(delItems);
                      deleteOrderItem2(items);
                   } else {
                      items.add(delItems);
                      deleteOrderItem2(items);
                   }
                }

HTH

regards

Andrew

On 23/07/06, Jason Johnston <co...@lojjic.net> wrote:
>
> >      >
> >      > Again the flow code is unchanged:
> >      >
> >      >         delItems = bizData.delItem ;
> >      >         var items = new java.util.Vector();
> >
> >
> > As delItems is now actually a widget, why can I not do this to extract
> > the value of the widget?:
> >
> > delItems = bizData.delItem.value;
> >
>
> Sorry, I'm working with an incomplete picture here... I don't know what
> bizData is or what bizData.delItem returns.  If it's the actual widget
> then yes, you should be able to do .value to get its value.  That value
> will be a Java String[] array, so if you have to get that into a Vector
> or Collection to satisfy whatever API you're passing it to then you'll
> need a conversion something like what I wrote in my previous reply.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
>      >
>      > Again the flow code is unchanged:
>      >
>      >         delItems = bizData.delItem ;
>      >         var items = new java.util.Vector();
> 
> 
> As delItems is now actually a widget, why can I not do this to extract 
> the value of the widget?:
> 
> delItems = bizData.delItem.value;
>  

Sorry, I'm working with an incomplete picture here... I don't know what 
bizData is or what bizData.delItem returns.  If it's the actual widget 
then yes, you should be able to do .value to get its value.  That value 
will be a Java String[] array, so if you have to get that into a Vector 
or Collection to satisfy whatever API you're passing it to then you'll 
need a conversion something like what I wrote in my previous reply.

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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,


Interesting, so how do users know what items they're deleting if you
> don't display them?


Believe me you me, I nearly choked at the final design cost of my website!
Suffice to say  a lovely table format was designed whereby the orderId,
artist name, title, qty, price, and then the delete checkbox are all
lovingly displayed to the end user. What is not needed on the end of that
row is the orderid again ;-)

Anyway, if that's really what you need then you can override the styling
> so that it does not display the item labels.
>
> Or something you might try first -- I haven't tried this so I don't know
> for sure if it will work -- is since it uses a (J)XPath expression to
> resolve the label, feed it an XPath expression that always returns an
> empty string.  Maybe like label-path="''"?



That works a treat. Nice one!

>     Should be list-type="checkbox".
> >
> >
> > Spot on again, thanks. When I select a value to be deleted none of them
> > are being deleted. If memory serves me correctly I need to convert the
> > array type to a collection and then obtain an iterator on the collection
> > right?
> >
> > Again the flow code is unchanged:
> >
> >         delItems = bizData.delItem ;
> >         var items = new java.util.Vector();


As delItems is now actually a widget, why can I not do this to extract the
value of the widget?:

delItems = bizData.delItem.value;

regards

Andrew

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Andrew wrote:
> Hi Jason,
> 
>     Sorry, I thought it was optional.  But no big deal, just set it to the
>     same as your value-path.
> 
> 
> 
> Unfortunately it is bit of a design issue and I do not need it displayed 
> on the screen. Is there no way at all this value can be optional?!

Interesting, so how do users know what items they're deleting if you 
don't display them?

Anyway, if that's really what you need then you can override the styling 
so that it does not display the item labels.

Or something you might try first -- I haven't tried this so I don't know 
for sure if it will work -- is since it uses a (J)XPath expression to 
resolve the label, feed it an XPath expression that always returns an 
empty string.  Maybe like label-path="''"?


>     Should be list-type="checkbox".
> 
> 
> Spot on again, thanks. When I select a value to be deleted none of them 
> are being deleted. If memory serves me correctly I need to convert the 
> array type to a collection and then obtain an iterator on the collection 
> right?
> 
> Again the flow code is unchanged:
> 
>         delItems = bizData.delItem ;
>         var items = new java.util.Vector();
>        
>         if (parseInt(bizData.quantity) || delItems != null) {
>             try {
>              
>                 if (delItems != null) {
>                
>                    if (delItems.iterator) { // A list of delItems have 
> been selected to be deleted.
>                       items.addAll(delItems);
>                       deleteOrderItem2(items);
>                    } else { //A single delItem has been selected to be 
> deleted.
>                       items.add(delItems);
>                       deleteOrderItem2(items);
>                    }
>                 }
> 

Does it have to be a java.util.Vector specifically or will any 
java.util.Collection or List do?  If the latter then you can just do:

var items = java.util.Arrays.asList(delItems); //returns java.util.List

If you really need a Vector you can then create one from that List:

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



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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,

Sorry, I thought it was optional.  But no big deal, just set it to the
> same as your value-path.



Unfortunately it is bit of a design issue and I do not need it displayed on
the screen. Is there no way at all this value can be optional?!

Should be list-type="checkbox".


Spot on again, thanks. When I select a value to be deleted none of them are
being deleted. If memory serves me correctly I need to convert the array
type to a collection and then obtain an iterator on the collection right?

Again the flow code is unchanged:

        delItems = bizData.delItem ;
        var items = new java.util.Vector();

        if (parseInt(bizData.quantity) || delItems != null) {
            try {

                if (delItems != null) {

                   if (delItems.iterator) { // A list of delItems have been
selected to be deleted.
                      items.addAll(delItems);
                      deleteOrderItem2(items);
                   } else { //A single delItem has been selected to be
deleted.
                      items.add(delItems);
                      deleteOrderItem2(items);
                   }
                }

regards

Andrew

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Andrew wrote:
> Hi Jason,
> 
>     <fd:selection-list type="flow-jxpath"
>          list-path="neworder/orderItems" value-path="ID"
>          label-path="(optional path to display label)" />
> 
> 
> how do I manage to avoid having to use the label-path attribute? Anytime 
> I try to keep it out I get an eror message saying that it is required! 

Sorry, I thought it was optional.  But no big deal, just set it to the 
same as your value-path.

> With it in I get a selection list instead of check boxes. My widget code 
> is as follows:
> widget:
> 
>      <ft:widget id= "delItem">
>        <fi:styling type="checkbox"/>
>      </ft:widget>

Check the docs: 
http://cocoon.apache.org/2.1/userdocs/widgets/widget_multivaluefield.html

Should be list-type="checkbox".

> 
> validation:
> 
>     <fd:multivaluefield id="delItem">
>       <fd:datatype base="string"/>
>       <fd:selection-list type="flow-jxpath" 
> list-path="neworder/orderItems" value-path="ID" />
>     </fd:multivaluefield>
> 
> regards
> 
> Andrew
> 
> 
> 


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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,

<fd:selection-list type="flow-jxpath"
>      list-path="neworder/orderItems" value-path="ID"
>      label-path="(optional path to display label)" />


how do I manage to avoid having to use the label-path attribute? Anytime I
try to keep it out I get an eror message saying that it is required! With it
in I get a selection list instead of check boxes. My widget code is as
follows:
widget:

     <ft:widget id= "delItem">
       <fi:styling type="checkbox"/>
     </ft:widget>

validation:

    <fd:multivaluefield id="delItem">
      <fd:datatype base="string"/>
      <fd:selection-list type="flow-jxpath" list-path="neworder/orderItems"
value-path="ID" />
    </fd:multivaluefield>

regards

Andrew

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Andrew wrote:
> Hi,
> is there a way I can build my list from accesing the required order 
> class I use in selection-list? In my jx I do:
> 
> <jx:forEach var="orderitem" items="${neworder.getOrderItems()}">
> 
> and then pull out the id I want in the checkbox as so:
> 
> <fi:styling value="${orderitem.getID()}" type="checkbox"/>
> 
> So would I be able to do:
> 
> selection-list src="neworder.getOrderItems ().get()" ? And if so how 
> would the selection-list know how to iterate through the object to pull 
> out all orderitem id's?

Use the flow-jxpath selection list type as described on 
http://cocoon.apache.org/2.1/userdocs/widgetconcepts/selectionlists.html. 
  Something like:

<fd:selection-list type="flow-jxpath"
     list-path="neworder/orderItems" value-path="ID"
     label-path="(optional path to display label)" />


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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi,
is there a way I can build my list from accesing the required order class I
use in selection-list? In my jx I do:

<jx:forEach var="orderitem" items="${neworder.getOrderItems()}">

and then pull out the id I want in the checkbox as so:

<fi:styling value="${orderitem.getID()}" type="checkbox"/>

So would I be able to do:

selection-list src="neworder.getOrderItems().get()" ? And if so how would
the selection-list know how to iterate through the object to pull out all
orderitem id's?

regards

Andrew

On 23/07/06, Andrew <an...@gmail.com> wrote:
>
> Hi Jason,
>
>
> > I'm guessing that this is displayed multiple times using a JX forEach
> > loop, rather than a repeater?
>
>
>
> that is correct. What benefit would there be to using a repeater over the
> method I am using?
>
> I think just using an fd:multivaluefield should work;
>
>
> No. Unfortunately this does not work, as it seems that at least one
> instance of the widget is required, where as in my case you will always
> start with zero items in a shopping cart, so there would be nothing to
> selectin the first instance. I also noticed that my checkbox was overwritten
> with a selection list box which is not what I want at all. I used the
> following:
>
> widget:
>
>
>      <ft:widget id= "delItem">
>        <fi:styling value="${orderitem.getID()}" type="checkbox"/>
>     </ft:widget>
>
> validation form:
>
>     <fd:multivaluefield id="delItem">
>       <fd:datatype base="string"/>
>     </fd:multivaluefield>
>
> the widget will
> > take care of parsing the multiple values from the request into an Array
> > object.  That would also simplify your flowscript since you'll always
> > get an Array rather than having to do the if/else for single vs.
> > multiple selection.
> >
> > However, usually multivaluefield widgets have their individual checkbox
> > items generated from a selection-list, rather than by iterating manually
> > and calling ft:widget multiple times with different values.  I'm not
> > sure how your approach will work with AJAX updates since it's a
> > nonstandard use of the widget.
>
>
> A repeater in itself, also, is of no use to me as this, as you know, only
> allows me to repeat a number of other widgets an unspecified amount of
> times.
>
> regards
>
> Andrew
>
>
>
>

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi Jason,


> I'm guessing that this is displayed multiple times using a JX forEach
> loop, rather than a repeater?



that is correct. What benefit would there be to using a repeater over the
method I am using?

I think just using an fd:multivaluefield should work;


No. Unfortunately this does not work, as it seems that at least one instance
of the widget is required, where as in my case you will always start with
zero items in a shopping cart, so there would be nothing to selectin the
first instance. I also noticed that my checkbox was overwritten with a
selection list box which is not what I want at all. I used the following:

widget:

     <ft:widget id= "delItem">
       <fi:styling value="${orderitem.getID()}" type="checkbox"/>
    </ft:widget>

validation form:

    <fd:multivaluefield id="delItem">
      <fd:datatype base="string"/>
    </fd:multivaluefield>

the widget will
> take care of parsing the multiple values from the request into an Array
> object.  That would also simplify your flowscript since you'll always
> get an Array rather than having to do the if/else for single vs.
> multiple selection.
>
> However, usually multivaluefield widgets have their individual checkbox
> items generated from a selection-list, rather than by iterating manually
> and calling ft:widget multiple times with different values.  I'm not
> sure how your approach will work with AJAX updates since it's a
> nonstandard use of the widget.


A repeater in itself, also, is of no use to me as this, as you know, only
allows me to repeat a number of other widgets an unspecified amount of
times.

regards

Andrew

Re: checkbox widget with datatype vector

Posted by Jason Johnston <co...@lojjic.net>.
Andrew wrote:
> Hi,
> I have a shopping cart system which enables a user to select a number of 
> items from their cart and delete them at the same time. This was working 
> perfectly before I chnaged everything to widgets because I need to use 
> ajax. What is happening now is that no matter how many items you select 
> to delete, only one item is ever deleted at a time. Now I suspect that 
> the problem lays with the datatype being used in fd:
> 
>     <fd:field id="delItem" required="true|false">
>       <fd:datatype base="string"/> // I tried boolean and nothing was 
> being deleted
>     </fd:field>
> 
> widget definition is:
> 
>      <ft:widget id= "delItem">
>         <fi:styling value="${orderitem.getID()}" type="checkbox"/>
>      </ft:widget>

I'm guessing that this is displayed multiple times using a JX forEach 
loop, rather than a repeater?

I think just using an fd:multivaluefield should work; the widget will 
take care of parsing the multiple values from the request into an Array 
object.  That would also simplify your flowscript since you'll always 
get an Array rather than having to do the if/else for single vs. 
multiple selection.

However, usually multivaluefield widgets have their individual checkbox 
items generated from a selection-list, rather than by iterating manually 
and calling ft:widget multiple times with different values.  I'm not 
sure how your approach will work with AJAX updates since it's a 
nonstandard use of the widget.

> flow:
> 
>         delItems = bizData.delItem ;
>         var items = new java.util.Vector();
>        
>         if (parseInt(bizData.quantity) || delItems != null) {
>             try {
>              
>                 if (delItems != null) {
>                
>                    if (delItems.iterator) { // A list of delItems have 
> been selected to be deleted.
>                       items.addAll(delItems);
>                       deleteOrderItem2(items);
>                    } else { //A single delItem has been selected to be 
> deleted.
>                       items.add(delItems);
>                       deleteOrderItem2(items);
>                    }
>                 }
> 



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


Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Hi,
I have managed to track down the email I first posted to the group
concerning this issue in 2004!:

http://mail-archives.apache.org/mod_mbox/cocoon-users/200411.mbox/%3Cs18f3876.079@cs-emo.csir.co.za%3E

The only thing I have changed, like I said earlier, is that I have now
implemented a widget system with required fields and I suspect that it is
the datatype declaration I have assigned to the widget that is causing the
problem here.

Any pointer will be most welcome.

regards

Andrew

On 23/07/06, Andrew <an...@gmail.com> wrote:
>
> Any ideas with this one guys?
>
> regards
>
> Andrew
>
>
> On 22/07/06, Andrew <an...@gmail.com> wrote:
> >
> > Hi,
> > I have a shopping cart system which enables a user to select a number of
> > items from their cart and delete them at the same time. This was working
> > perfectly before I chnaged everything to widgets because I need to use ajax.
> > What is happening now is that no matter how many items you select to delete,
> > only one item is ever deleted at a time. Now I suspect that the problem lays
> > with the datatype being used in fd:
> >
> >     <fd:field id="delItem" required="true|false">
> >       <fd:datatype base="string"/> // I tried boolean and nothing was
> > being deleted
> >     </fd:field>
> >
> > widget definition is:
> >
> >      <ft:widget id= "delItem">
> >         <fi:styling value="${orderitem.getID()}" type="checkbox"/>
> >      </ft:widget>
> >
> > flow:
> >
> >         delItems = bizData.delItem ;
> >         var items = new java.util.Vector();
> >
> >         if (parseInt(bizData.quantity) || delItems != null) {
> >             try {
> >
> >                 if (delItems != null) {
> >
> >                    if (delItems.iterator) { // A list of delItems have
> > been selected to be deleted.
> >                       items.addAll(delItems);
> >                       deleteOrderItem2(items);
> >                    } else { //A single delItem has been selected to be
> > deleted.
> >                       items.add(delItems);
> >                       deleteOrderItem2(items);
> >                    }
> >                 }
> >
> > Any ideas what I am missing here?
> >
> > regards
> >
> > Andrew
> >
>
>

Re: checkbox widget with datatype vector

Posted by Andrew <an...@gmail.com>.
Any ideas with this one guys?

regards

Andrew

On 22/07/06, Andrew <an...@gmail.com> wrote:
>
> Hi,
> I have a shopping cart system which enables a user to select a number of
> items from their cart and delete them at the same time. This was working
> perfectly before I chnaged everything to widgets because I need to use ajax.
> What is happening now is that no matter how many items you select to delete,
> only one item is ever deleted at a time. Now I suspect that the problem lays
> with the datatype being used in fd:
>
>     <fd:field id="delItem" required="true|false">
>       <fd:datatype base="string"/> // I tried boolean and nothing was
> being deleted
>     </fd:field>
>
> widget definition is:
>
>      <ft:widget id= "delItem">
>         <fi:styling value="${orderitem.getID()}" type="checkbox"/>
>      </ft:widget>
>
> flow:
>
>         delItems = bizData.delItem ;
>         var items = new java.util.Vector();
>
>         if (parseInt(bizData.quantity) || delItems != null) {
>             try {
>
>                 if (delItems != null) {
>
>                    if (delItems.iterator) { // A list of delItems have
> been selected to be deleted.
>                       items.addAll(delItems);
>                       deleteOrderItem2(items);
>                    } else { //A single delItem has been selected to be
> deleted.
>                       items.add(delItems);
>                       deleteOrderItem2(items);
>                    }
>                 }
>
> Any ideas what I am missing here?
>
> regards
>
> Andrew
>