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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to