Warren,

If you don't mind your "wicket:id"s becoming rather misleading and arguably
slightly harder to follow (magical) Java, you can even do ...

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) {
        setDefaultModel(new CompoundPropertyModel<HomePage>(this));
        Form<Void> form = new Form<Void>("form"); 
        add(form); 
        form.add(new ListChoice<Vendor>("vendor", vendors)); 
        Form<Vendor> editForm = new Form<Vendor>("vendorEditForm");
        add(editForm);
        editForm.add(new TextField<String>("vendor.name"));
    }
    private class Vendor {
        private String name;
        Vendor(String name) {this.name = name;}
        @Override public String toString() {return name;}
    }
}

I haven't worked out how to properly paste html into nabble, so drop me a
line at the jWeekend site if you want the template code to go with this, or
a QuickStart. 

Any comments on the type-parameters used above anybody?!

Regards - Cemal 
jWeekend 
OO & Java Technologies, Wicket Training and Development 
http://jWeekend.com


Warren Bell-3 wrote:
> 
> In your second example the Vendor in the vendorModel becomes the
> selected Vendor from the ListChoice and that Vendor name property
> becomes the value of the TextField? 
> 
> -----Original Message-----
> From: jWeekend [mailto:jweekend_for...@cabouge.com] 
> Sent: Friday, August 14, 2009 3:47 PM
> To: users@wicket.apache.org
> Subject: Re: Model question ?
> 
> 
> 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: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>> 
>> 
> 
> --
> 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: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Model-question---tp24978225p24980619.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to