You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dukehoops <ni...@doppelganger.com> on 2008/10/08 00:44:42 UTC

please review my CompoundPropertyModel use

The following code works (have unit tests) but I would appreciate a code
review from someone.

Legend
MyPojo - bean backing up form 
MyProperty - another POJO that is property of MyPojo (MyPojo has field
'myProperty' of type MyProperty)
MyFormComponent - custom form component that displays/manipulates MyProperty
(myProperty == myFormComponent.getModelObject())

In particular, I want to ensure that when MyComponent's modelObject is
updated, so is formBean's property (to be more precise, that the two
reference the same object)

//inside page:

IModel formModel = new CompoundPropertyModel(MyPojo);
Form form = new Form("form", formModel);
page.add(form);

MyFormComponent myComp = new MyFormComponent("myProperty", new
PropertyModel(formModel, "myProperty"));
form.add(myComp);

and constructor:
MyFormComponent(wicketId, model)
{
super(wicketId, model);
}

-----
----------------
Nikita Tovstoles
vside.com
----------------

-- 
View this message in context: http://www.nabble.com/please-review-my-CompoundPropertyModel-use-tp19868935p19868935.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: please review my CompoundPropertyModel use

Posted by Ned Collyer <ne...@gmail.com>.
Perhaps I don't understand your use case.

I'm using CPM all over the shop, and letting auto CPM propagation take care
of itself.

If the property is obtained from some other way, then obviously you would
need to supply it to the form field - in the same way there are multi
constructors for most form fields.  Perhaps open the source of "TextField"
and piece together how that behaves.

Rgds

Ned


dukehoops wrote:
> 
> I thought that as well, but turns out in that case
> MyFormComponent.getModelObject() returns MyPojo, and NOT MyProperty. That
> presents two problems:
> -MyFormComponent does not really need to know of MyPojo to begin with
> (what if MyProperty is obtained some other way)
> -in MyFormComponent.convertInput, I need to eventually
> setConvertedInput(MyProperty), and in onBeforeRender the corollary
> getModelObject.  
> 

-- 
View this message in context: http://www.nabble.com/please-review-my-CompoundPropertyModel-use-tp19868935p19871374.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: please review my CompoundPropertyModel use

Posted by dukehoops <ni...@doppelganger.com>.
I thought that as well, but turns out in that case
MyFormComponent.getModelObject() returns MyPojo, and NOT MyProperty. That
presents two problems:
-MyFormComponent does not really need to know of MyPojo to begin with (what
if MyProperty is obtained some other way)
-in MyFormComponent.convertInput, I need to eventually
setConvertedInput(MyProperty), and in onBeforeRender the corollary
getModelObject.  


Ned Collyer wrote:
> 
> You should be able to do
> 
> Form form = new Form("form", new CompoundPropertyModel(MyPojo));
> page.add(form);
> 
> form.add(new MyFormComponent("myProperty"));
> 
> 
> See
> http://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels
> 
> 
> 


-----
----------------
Nikita Tovstoles
vside.com
----------------

-- 
View this message in context: http://www.nabble.com/please-review-my-CompoundPropertyModel-use-tp19868935p19870526.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: please review my CompoundPropertyModel use

Posted by Ned Collyer <ne...@gmail.com>.
You should be able to do

Form form = new Form("form", new CompoundPropertyModel(MyPojo));
page.add(form);

form.add(new MyFormComponent("myProperty"));


See
http://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels



dukehoops wrote:
> 
> The following code works (have unit tests) but I would appreciate a code
> review from someone.
> 
> Legend
> MyPojo - bean backing up form 
> MyProperty - another POJO that is property of MyPojo (MyPojo has field
> 'myProperty' of type MyProperty)
> MyFormComponent - custom form component that displays/manipulates
> MyProperty (myProperty == myFormComponent.getModelObject())
> 
> In particular, I want to ensure that when MyComponent's modelObject is
> updated, so is formBean's property (to be more precise, that the two
> reference the same object)
> 
> //inside page:
> 
> IModel formModel = new CompoundPropertyModel(MyPojo);
> Form form = new Form("form", formModel);
> page.add(form);
> 
> MyFormComponent myComp = new MyFormComponent("myProperty", new
> PropertyModel(formModel, "myProperty"));
> form.add(myComp);
> 
> and constructor:
> MyFormComponent(wicketId, model)
> {
> super(wicketId, model);
> }
> 

-- 
View this message in context: http://www.nabble.com/please-review-my-CompoundPropertyModel-use-tp19868935p19870462.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