The basic idea in the DVD Store is that instead of creating view objects with a property indicating the item is selected, you can map a checkbox to a boolean in a Map indexed by the item in questions. So, you'll see things like:
cartSelection is being backed by a simple map:
Map<Product,Boolean> cartSelection = new HashMap<Product,Boolean>();
That map gets updated whenever the form is submitted. It's a fairly simply process to iterate over the map and find out what the selected objects are. In this particular case, the updateCart() method iterates through the known items and checks which are marked as selected. Take a look at search.addAllToCart for another use.
I guess I don't understand very well. The examples aren't very clear for something that was kicked off with seamgen. Which object does the Map go into (the list or home object)? Do those have to be marked as @Stateful then? I'm just lost trying to match up a seamgened app to everything else. I'm still trying to wrap my head around how this whole thing works.
It doesn't really matter where the Map goes. I think the most convenient place to put it is on whatever component has the action that will be using the data. Where do you want to be performing an action that uses the the selected objects?
Ok, stupid question then... does the action have to be a Session bean?
Ok, don't mind me. I tried on a different project and it worked fine. I'm not sure why it doesn't work on the original project yet though. Thanks for your help.
Hi smith I am also looking for one such example which you were looking for, can you post your sample code to select multiple rows in the datatable using checkboxes and delete them all in just one click of delete button.
\ 01. Apr 2008, 20:38 CET Link
However, we are trying to add checkboxes to the datatables so teh user can select multiple items and then delete everything in one click. How exactly do we go about that? I thought it would be very common and I've looked at the Dvd store example for help, but I'm missing something on how you tie together the submit with the checkboxes. The stuff already posted on this problem hasn't been much help.