Warren,
... and if you prefer using a CPM for your "vendorEditForm"s:
public class HomePage extends WebPage {
private List<Vendor> vendors = Arrays.asList(new Vendor("v1"),
new
Vendor("v2"));
private Vendor vendor = new Vendor("default vendor");
public HomePage(final PageParameters parameters) {
IModel vendorModel = new PropertyModel<Vendor>(this, "vendor");
Form<Void> form = new Form<Void>("form");
add(form);
// use your existing LDM instead of this hard-wired
// List of vendors but
// make sure you merge your edits properly!
form.add(new ListChoice<Vendor>("vendors",
vendorModel, vendors));
// using a PropertyModel per field
Form<Void> editForm1 = new Form<Void>("vendorEditForm1");
add(editForm1);
editForm1.add(new TextField<Vendor>("name",
new PropertyModel<Vendor>(this, "vendor.name")));
// using a CompoundPropertyModel
Form<Vendor> editForm2 = new Form<Vendor>("vendorEditForm2",
new CompoundPropertyModel<Vendor>(vendorModel));
add(editForm2);
editForm2.add(new TextField<Vendor>("name"));
}
private class Vendor implements Serializable{
private String name;
protected Vendor(String name) {this.name = name;}
public String toString(){return name;}
// safer to have accessors & mutators
}
// safer to have accessors & mutators
}
Regards - Cemal
jWeekend
OO & Java Technologies, Wicket Training and Development
http://jWeekend.com
Warren Bell-3 wrote:
>
> How should I set up my model for the following situation. I have a form
> with a ListChoice and a TextField. The TextField needs to access a
> property of the object selected of the ListChoice. I have it all working
> using a ValueMap, but that seems like overkill to use a ValueMap for one
> object. Here is how I have it:
>
> super(new CompoundPropertyModel<ValueMap>(new ValueMap()));
>
> ListChoice<Vendor> vendorListChoice = new ListChoice<Vendor>("vendor",
> new LoadableDetachableModel<List<Vendor>>(){...}, new
> IChoiceRenderer<Vendor>(){...});
>
> TextField<String> accountNumberField = new
> TextField<String>("vendor.accountNumber");
>
> I thought I could do something like this:
>
> super(new CompoundPropertyModel<Vendor>(new Vendor()));
>
> The ListChoice is the same as above and the TextField like this:
>
> TextField<String> accountNumberField = new
> TextField<String>("accountNumber");
>
> The problem with this is that the ListChoice is trying to set a property
> on the model named vendor when I realy want the selected ListChoice
> vendor object be the model object and have the TextField access the
> accountNumber property of the ListChoice vendor.
>
> How should I set up my model to deal with this type of situation or is a
> ValueMap the best way?
>
> Thanks,
>
> Warren
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://www.nabble.com/Model-question---tp24978225p24979787.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]