You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Warren Bell <Wa...@clarksnutrition.com> on 2009/08/14 22:42:30 UTC
Model question ?
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Model question ?
Posted by Eelco Hillenius <ee...@gmail.com>.
> Is there any issues you need to be concerned with when using the page
> itself as the model object?
I don't think so.
Eelco
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Model question ?
Posted by Martijn Dashorst <ma...@gmail.com>.
Just don't pass the model to another page (also don't do this for
anon-inner classes, or nested classes that carry a this pointer to the
page)
Martijn
On Sun, Aug 16, 2009 at 4:04 AM, Warren Bell<Wa...@clarksnutrition.com> wrote:
> Is there any issues you need to be concerned with when using the page
> itself as the model object?
>
> Warren
>
> -----Original Message-----
> From: jWeekend [mailto:jweekend_forums@cabouge.com]
> Sent: Friday, August 14, 2009 5:43 PM
> To: users@wicket.apache.org
> Subject: RE: Model question ?
>
>
> 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_forums@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-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Model question ?
Posted by Warren Bell <Wa...@clarksnutrition.com>.
Is there any issues you need to be concerned with when using the page
itself as the model object?
Warren
-----Original Message-----
From: jWeekend [mailto:jweekend_forums@cabouge.com]
Sent: Friday, August 14, 2009 5:43 PM
To: users@wicket.apache.org
Subject: RE: Model question ?
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_forums@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-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Model question ?
Posted by jWeekend <jw...@cabouge.com>.
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_forums@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-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Model question ?
Posted by jWeekend <jw...@cabouge.com>.
Warren,
Exactly - and in a very Wicket way!
Just drop the code into your IDE and run it - if there are no typos (other
than the type parameter to the TextFields - the compiler can't help you
here!) it just works.
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_forums@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-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Model-question---tp24978225p24980016.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Model question ?
Posted by Warren Bell <Wa...@clarksnutrition.com>.
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_forums@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Model question ?
Posted by jWeekend <jw...@cabouge.com>.
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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Model question ?
Posted by jWeekend <jw...@cabouge.com>.
Warren,
Something like this?
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) {
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", new
PropertyModel<Vendor>(this, "vendor"), vendors));
Form<Void> editForm = new Form<Void>("vendorEditForm");
add(editForm);
editForm.add(new TextField<Vendor>("name", new
PropertyModel<Vendor>(this, "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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Model-question---tp24978225p24979290.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org