On 3/24/06,
Igor Vaynberg <[EMAIL PROTECTED]> wrote:
public class MyPage extends WebPage {
private Map<Long,Integer> selection=new HashMap<Long,Integer>();
public MyPage() {
IModel categories=....
Form form=new Form("form");
add(form);
firm.add(new ListView("quantities", categories) {
public void populateItem(ListItem item) {
ProductCategory cat=item.getModelObject();
final Long catId= cat.getId();
// this model will populate an appropriate entry in the selection map
IModel selectionModel=new Model() {
setObject(Component c, Object o) {
selection.put (catId, (Integer)o);
}
Object getObject(Component c) {
return selection.get(catId);
}
}
add(new DropDownChoice("qty", selectionModel, .....)
}
});
form.add(new Button() { onSubmit() { System.out.println(selection.toString()); } }
...
-Igor
On 3/24/06, Vincent Jenks <[EMAIL PROTECTED]> wrote:It makes sense but I wouldn't know how to begin (I'm rather new to Java as well as Wicket)...is there an example in the wicket-examples somewhere?
Would I just create a Map inside of the ListView?On 3/24/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:if you are using a listview there is really no way to use a compound property model. here is what you can do:
on your page create a map:configid->qty
then to the dropdown choices assign a model that will read/write a key from this map.
so when the form submits you endup with a filled in map in your page.
makes sense?
-IgorOn 3/24/06, Vincent Jenks < [EMAIL PROTECTED]> wrote:I've attached a screenshot of what this page does.
Basically, the page you see receives a Product object in the constructor when it is called from the previous page. Each Product has a List of Configuration objects...which you see listed in the screenshot ( i.e. 1 Bone In Ham Half 7-10 lbs @ $99.00). Admins can define many product Configurations that the user can select on this screen. The Configurations have an inverse relationship back to the Product so when the Configuration is added to the cart, the Product can be referenced as well.
My problem is; in this form, how can I bind a single Configuration when there are (potentially) several, per-product?
My thinking was; I could add the Product to the ShoppingCart session bean instead and it would carry the product Configuration(s) with it...assuming I could grab each Configuration from the ListView in the form (where you see the 1 "Bone In Ham Half 7-10 lbs" text and the DropDownChoice lists) and manually create the Configuration object(s) and add them to the Product before submitting the form.
Does this make sense?
Thanks again!!On 3/24/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:do you have a screenshot/mockup of the form? seeing it would help.
so there is a list of configurations? and the user can click on one and edit it?
-IgorOn 3/24/06, Vincent Jenks <[EMAIL PROTECTED]> wrote:I've got a form where I can't exactly bind a model object because of the way the form is used. On this page, the user selects from a list of product configurations (ProductConfiguration class) which belong to a Product object....so there is a one-to-many Product->ProductConfiguration. I can't pass a ProductConfiguration object into the CompoundPropertyModel because the user may choose more than one (or can I?) I'm thinking I need to bind the Product and manually add the ProductConfiguration objects to the product before submitting.
If I do it this way...how can I access each of the form fields programmatically, individually? In other words...can form field values be called w/o using a CompoundPropertyModel if needed?
Also, if there's a better way to do this, please let me know!
Thanks!