There may be a much better way of doing what I'm trying to do, and if
so, I'd love to hear about it. But what I thought would be simple seems
to be eluding me here.
I have a form with a dynamic number of dropdowns. I'm populating them
using a ListView, and the display is working fine. The trouble is that
in my onSubmit(), I now need to get at the selections made for each, and
I don't know how to get back the ListItems; the only methods which
really seem to expose these are populateItem() and renderItem(), which
run before onSubmit(). Is there a way to get at these? Or can you
suggest another way to structure this so that I have the access needed?
A little more explanation and some sample code is below.
Thanks,
-- Scott Sauyet
The user is purchasing tickets in a section of some venue. That section
will have different buyer types, each with its own price, description,
and maximum allowed tickets. The user should be able to choose, for
instance, two adult tickets, one senior ticket, and three child tickets.
But the buyer types available are data driven; I can't simply
hard-code separate dropdowns for each.
public static class SectionForm extends Form {
private PriceSection section;
public SectionForm(String id, PriceSection section) {
super(id);
this.section = section;
add(new Label("section-description", section.toString()));
List<BuyerType> buyerTypes = section.getBuyerTypes();
add(new ListView("buyer-type", buyerTypes) {
public List<String> quantities;
public void populateItem(ListItem listItem) {
BuyerType buyerType = (BuyerType)
listItem.getModelObject();
listItem.add(new Label("description",
buyerType.getDescription()));
listItem.add(new Label("price",
CURRENCY.format(buyerType.getPrice())));
quantities = allowedQuantities(buyerType);
listItem.add(new DropDownChoice("quantity",
new Model(quantities.get(0)), quantities));
}
});
}
public void onSubmit() {
System.out.println("Chose section " + section);
ListView types = (ListView) get("buyer-type");
System.out.println(((List) types.getModelObject())
.get(0).getClass());
/// ????
for (Object obj: types.?????()) { // What do I do here?
/// ????
ListItem item = (ListItem) obj;
BuyerType type = (BuyerType) item.getModelObject();
String choice = ((DropDownChoice) item.get("quantity"))
.getModelValue();
System.out.println("\t" + type.getDescription()
+ ": " + choice + " @ "
+ CURRENCY.format(type.getPrice()));
}
}
// ...
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]