You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jan Ferko <ju...@gmail.com> on 2010/10/22 18:29:00 UTC

Fwd: Nested CompoundModel

Hi,

I am doing on form which consists of multiple panels and data object
hierarchy to them.

For example:

class Data1 {
   Data2 data2;
}

class Data2 {
   Data3 data3;
}

class Data3 {
   String str;
}


class MyForm extends Form{
   public MyForm(id, model){
       super(id, model);
       this.add(new MyPanel(id2, new
CompoundPropertyModel(this.getModelObject().getData2());
   }
}

and very simillar in MyPanel with data3 object, but...

I have problem with updating my data model wicket always throw
WickedMessage:

Attempted to set property value on a null object.

Do anyone know how to solve this?

Thanks for help
Jan Ferko

Re: Fwd: Nested CompoundModel

Posted by Jan Ferko <ju...@gmail.com>.
I accidently sent it incomplete  ... here is full code

RepeatingView rp = new RepeatingView();
for(int i =0; i< n; i++){
   WebMarkupContainer parent = new WebMarkupContainer(rp.newChildID());
   rp.add(parent);

   MyPanelData data =new MyPanelData();
   this.getModelObject.getList().add(data);
   MyPanel panel = new MyPanel("panel", new CompoundPropertyModel(data));
   parent.add(panel);
}

Jan Ferko

2010/10/24 Jan Ferko <ju...@gmail.com>

> Thanks a lot, it worked great.
>
> I have one more question. I have to create same panel multiple times ,
> based on user output into the form and i have list of panel data model
> object inside my form data object. Is it better to generate panels in page
> class and then passed list of panels into form constructor and use ListView
> or generate it inside form with RepeatingView and create new instance of
> PanelData in Cycle and setting it on Panel and saving it to list like
> this...
>
> RepeatingView rp = new RepeatingView();
> for(int i =0; i< n; i++){
>    WebMarkupContainer parent = new WebMarkupContainer(rp.newChildID());
>
> }
>
> 2010/10/22 Jeremy Thomerson <je...@wickettraining.com>
>
> On Fri, Oct 22, 2010 at 11:38 AM, Sven Meier <sv...@meiers.net> wrote:
>>
>> > Hi Jan,
>> >
>> > when are data2 and data3 initialized? They seems to be null when you put
>> up
>> > your models.
>> >
>> > Most of the time it's a bad idea to pull something out of a model and
>> put
>> > it back into another model.
>> > Do this instead:
>> >
>> >    this.add(new MyPanel(id2, new PropertyModel(model, "data2")));
>> >
>> > Then in MyPanel:
>> >
>> >    public MyPanel(id, model){
>> >         super(id, new CompoundPropertyModel(model));
>> >
>> > This has the following advantages:
>> > - MyPanel's model is always in sync with the model of MyForm.
>> > - MyPanel's usage of CompoundPropertyModel is hidden from the outside.
>> If
>> > MyPanel want's to utilize a CompoundPropertyModel (because it doesn't
>> set
>> > the model on its contained components), it should set it up by itself.
>> >
>> > HTH
>> >
>> > Sven
>>
>>
>> Sven is spot-on, and this method he showed you above will absolutely save
>> you some bugs down the road!
>>
>> Thanks Sven!!
>>
>> --
>> Jeremy Thomerson
>> http://wickettraining.com
>> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>>
>
>
>
> --
> Jan Ferko,
> julyloov@gmail.com
>



-- 
Jan Ferko,
julyloov@gmail.com

Re: Fwd: Nested CompoundModel

Posted by Jan Ferko <ju...@gmail.com>.
Thanks a lot everyone



On 10/26/2010 03:17 AM, Pedro Santos wrote:
> If you have n MyPanelData on a page, you will be fine with the
> RepeatingView. Otherwise use the Listview to generate the correct number of
> items with MyPanel each render.
>
> On Mon, Oct 25, 2010 at 8:19 PM, Jan Ferko<ju...@gmail.com>  wrote:
>
>    
>>   well, I have all fields which have to be create dynamicaly grouped in one
>> panel. So whole panel is
>>
>> 2010/10/25 Jeremy Thomerson<je...@wickettraining.com>
>>
>>      
>>> What part is dynamic / dependent on the form?
>>>
>>> On Sun, Oct 24, 2010 at 3:59 PM, Jan Ferko<ju...@gmail.com>  wrote:
>>>
>>>        
>>>> Thanks a lot, it worked great.
>>>>
>>>> I have one more question. I have to create same panel multiple times ,
>>>> based
>>>> on user output into the form and i have list of panel data model object
>>>> inside my form data object. Is it better to generate panels in page
>>>>          
>> class
>>      
>>>> and then passed list of panels into form constructor and use ListView
>>>>          
>> or
>>      
>>>> generate it inside form with RepeatingView and create new instance of
>>>> PanelData in Cycle and setting it on Panel and saving it to list like
>>>> this...
>>>>
>>>> RepeatingView rp = new RepeatingView();
>>>> for(int i =0; i<  n; i++){
>>>>    WebMarkupContainer parent = new WebMarkupContainer(rp.newChildID());
>>>>
>>>> }
>>>>
>>>> 2010/10/22 Jeremy Thomerson<je...@wickettraining.com>
>>>>
>>>>          
>>>>> On Fri, Oct 22, 2010 at 11:38 AM, Sven Meier<sv...@meiers.net>
>>>>>            
>> wrote:
>>      
>>>>>            
>>>>>> Hi Jan,
>>>>>>
>>>>>> when are data2 and data3 initialized? They seems to be null when
>>>>>>              
>> you
>>      
>>>> put
>>>>          
>>>>> up
>>>>>            
>>>>>> your models.
>>>>>>
>>>>>> Most of the time it's a bad idea to pull something out of a model
>>>>>>              
>> and
>>      
>>>> put
>>>>          
>>>>>> it back into another model.
>>>>>> Do this instead:
>>>>>>
>>>>>>     this.add(new MyPanel(id2, new PropertyModel(model, "data2")));
>>>>>>
>>>>>> Then in MyPanel:
>>>>>>
>>>>>>     public MyPanel(id, model){
>>>>>>          super(id, new CompoundPropertyModel(model));
>>>>>>
>>>>>> This has the following advantages:
>>>>>> - MyPanel's model is always in sync with the model of MyForm.
>>>>>> - MyPanel's usage of CompoundPropertyModel is hidden from the
>>>>>>              
>>> outside.
>>>        
>>>> If
>>>>          
>>>>>> MyPanel want's to utilize a CompoundPropertyModel (because it
>>>>>>              
>> doesn't
>>      
>>>> set
>>>>          
>>>>>> the model on its contained components), it should set it up by
>>>>>>              
>>> itself.
>>>        
>>>>>> HTH
>>>>>>
>>>>>> Sven
>>>>>>              
>>>>>
>>>>> Sven is spot-on, and this method he showed you above will absolutely
>>>>>            
>>> save
>>>        
>>>>> you some bugs down the road!
>>>>>
>>>>> Thanks Sven!!
>>>>>
>>>>> --
>>>>> Jeremy Thomerson
>>>>> http://wickettraining.com
>>>>> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>>>>>
>>>>>            
>>>>
>>>>
>>>> --
>>>> Jan Ferko,
>>>> julyloov@gmail.com
>>>>
>>>>          
>>>
>>>
>>> --
>>> Jeremy Thomerson
>>> http://wickettraining.com
>>> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>>>
>>>        
>>
>>
>> --
>> Jan Ferko,
>> julyloov@gmail.com
>>
>>      
>
>
>    


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


Re: Fwd: Nested CompoundModel

Posted by Pedro Santos <pe...@gmail.com>.
If you have n MyPanelData on a page, you will be fine with the
RepeatingView. Otherwise use the Listview to generate the correct number of
items with MyPanel each render.

On Mon, Oct 25, 2010 at 8:19 PM, Jan Ferko <ju...@gmail.com> wrote:

>  well, I have all fields which have to be create dynamicaly grouped in one
> panel. So whole panel is
>
> 2010/10/25 Jeremy Thomerson <je...@wickettraining.com>
>
> > What part is dynamic / dependent on the form?
> >
> > On Sun, Oct 24, 2010 at 3:59 PM, Jan Ferko <ju...@gmail.com> wrote:
> >
> > > Thanks a lot, it worked great.
> > >
> > > I have one more question. I have to create same panel multiple times ,
> > > based
> > > on user output into the form and i have list of panel data model object
> > > inside my form data object. Is it better to generate panels in page
> class
> > > and then passed list of panels into form constructor and use ListView
> or
> > > generate it inside form with RepeatingView and create new instance of
> > > PanelData in Cycle and setting it on Panel and saving it to list like
> > > this...
> > >
> > > RepeatingView rp = new RepeatingView();
> > > for(int i =0; i< n; i++){
> > >   WebMarkupContainer parent = new WebMarkupContainer(rp.newChildID());
> > >
> > > }
> > >
> > > 2010/10/22 Jeremy Thomerson <je...@wickettraining.com>
> > >
> > > > On Fri, Oct 22, 2010 at 11:38 AM, Sven Meier <sv...@meiers.net>
> wrote:
> > > >
> > > > > Hi Jan,
> > > > >
> > > > > when are data2 and data3 initialized? They seems to be null when
> you
> > > put
> > > > up
> > > > > your models.
> > > > >
> > > > > Most of the time it's a bad idea to pull something out of a model
> and
> > > put
> > > > > it back into another model.
> > > > > Do this instead:
> > > > >
> > > > >    this.add(new MyPanel(id2, new PropertyModel(model, "data2")));
> > > > >
> > > > > Then in MyPanel:
> > > > >
> > > > >    public MyPanel(id, model){
> > > > >         super(id, new CompoundPropertyModel(model));
> > > > >
> > > > > This has the following advantages:
> > > > > - MyPanel's model is always in sync with the model of MyForm.
> > > > > - MyPanel's usage of CompoundPropertyModel is hidden from the
> > outside.
> > > If
> > > > > MyPanel want's to utilize a CompoundPropertyModel (because it
> doesn't
> > > set
> > > > > the model on its contained components), it should set it up by
> > itself.
> > > > >
> > > > > HTH
> > > > >
> > > > > Sven
> > > >
> > > >
> > > > Sven is spot-on, and this method he showed you above will absolutely
> > save
> > > > you some bugs down the road!
> > > >
> > > > Thanks Sven!!
> > > >
> > > > --
> > > > Jeremy Thomerson
> > > > http://wickettraining.com
> > > > *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
> > > >
> > >
> > >
> > >
> > > --
> > > Jan Ferko,
> > > julyloov@gmail.com
> > >
> >
> >
> >
> > --
> > Jeremy Thomerson
> > http://wickettraining.com
> > *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
> >
>
>
>
> --
> Jan Ferko,
> julyloov@gmail.com
>



-- 
Pedro Henrique Oliveira dos Santos

Re: Fwd: Nested CompoundModel

Posted by Jan Ferko <ju...@gmail.com>.
 well, I have all fields which have to be create dynamicaly grouped in one
panel. So whole panel is

2010/10/25 Jeremy Thomerson <je...@wickettraining.com>

> What part is dynamic / dependent on the form?
>
> On Sun, Oct 24, 2010 at 3:59 PM, Jan Ferko <ju...@gmail.com> wrote:
>
> > Thanks a lot, it worked great.
> >
> > I have one more question. I have to create same panel multiple times ,
> > based
> > on user output into the form and i have list of panel data model object
> > inside my form data object. Is it better to generate panels in page class
> > and then passed list of panels into form constructor and use ListView or
> > generate it inside form with RepeatingView and create new instance of
> > PanelData in Cycle and setting it on Panel and saving it to list like
> > this...
> >
> > RepeatingView rp = new RepeatingView();
> > for(int i =0; i< n; i++){
> >   WebMarkupContainer parent = new WebMarkupContainer(rp.newChildID());
> >
> > }
> >
> > 2010/10/22 Jeremy Thomerson <je...@wickettraining.com>
> >
> > > On Fri, Oct 22, 2010 at 11:38 AM, Sven Meier <sv...@meiers.net> wrote:
> > >
> > > > Hi Jan,
> > > >
> > > > when are data2 and data3 initialized? They seems to be null when you
> > put
> > > up
> > > > your models.
> > > >
> > > > Most of the time it's a bad idea to pull something out of a model and
> > put
> > > > it back into another model.
> > > > Do this instead:
> > > >
> > > >    this.add(new MyPanel(id2, new PropertyModel(model, "data2")));
> > > >
> > > > Then in MyPanel:
> > > >
> > > >    public MyPanel(id, model){
> > > >         super(id, new CompoundPropertyModel(model));
> > > >
> > > > This has the following advantages:
> > > > - MyPanel's model is always in sync with the model of MyForm.
> > > > - MyPanel's usage of CompoundPropertyModel is hidden from the
> outside.
> > If
> > > > MyPanel want's to utilize a CompoundPropertyModel (because it doesn't
> > set
> > > > the model on its contained components), it should set it up by
> itself.
> > > >
> > > > HTH
> > > >
> > > > Sven
> > >
> > >
> > > Sven is spot-on, and this method he showed you above will absolutely
> save
> > > you some bugs down the road!
> > >
> > > Thanks Sven!!
> > >
> > > --
> > > Jeremy Thomerson
> > > http://wickettraining.com
> > > *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
> > >
> >
> >
> >
> > --
> > Jan Ferko,
> > julyloov@gmail.com
> >
>
>
>
> --
> Jeremy Thomerson
> http://wickettraining.com
> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>



-- 
Jan Ferko,
julyloov@gmail.com

Re: Fwd: Nested CompoundModel

Posted by Jeremy Thomerson <je...@wickettraining.com>.
What part is dynamic / dependent on the form?

On Sun, Oct 24, 2010 at 3:59 PM, Jan Ferko <ju...@gmail.com> wrote:

> Thanks a lot, it worked great.
>
> I have one more question. I have to create same panel multiple times ,
> based
> on user output into the form and i have list of panel data model object
> inside my form data object. Is it better to generate panels in page class
> and then passed list of panels into form constructor and use ListView or
> generate it inside form with RepeatingView and create new instance of
> PanelData in Cycle and setting it on Panel and saving it to list like
> this...
>
> RepeatingView rp = new RepeatingView();
> for(int i =0; i< n; i++){
>   WebMarkupContainer parent = new WebMarkupContainer(rp.newChildID());
>
> }
>
> 2010/10/22 Jeremy Thomerson <je...@wickettraining.com>
>
> > On Fri, Oct 22, 2010 at 11:38 AM, Sven Meier <sv...@meiers.net> wrote:
> >
> > > Hi Jan,
> > >
> > > when are data2 and data3 initialized? They seems to be null when you
> put
> > up
> > > your models.
> > >
> > > Most of the time it's a bad idea to pull something out of a model and
> put
> > > it back into another model.
> > > Do this instead:
> > >
> > >    this.add(new MyPanel(id2, new PropertyModel(model, "data2")));
> > >
> > > Then in MyPanel:
> > >
> > >    public MyPanel(id, model){
> > >         super(id, new CompoundPropertyModel(model));
> > >
> > > This has the following advantages:
> > > - MyPanel's model is always in sync with the model of MyForm.
> > > - MyPanel's usage of CompoundPropertyModel is hidden from the outside.
> If
> > > MyPanel want's to utilize a CompoundPropertyModel (because it doesn't
> set
> > > the model on its contained components), it should set it up by itself.
> > >
> > > HTH
> > >
> > > Sven
> >
> >
> > Sven is spot-on, and this method he showed you above will absolutely save
> > you some bugs down the road!
> >
> > Thanks Sven!!
> >
> > --
> > Jeremy Thomerson
> > http://wickettraining.com
> > *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
> >
>
>
>
> --
> Jan Ferko,
> julyloov@gmail.com
>



-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*

Re: Fwd: Nested CompoundModel

Posted by Jan Ferko <ju...@gmail.com>.
Thanks a lot, it worked great.

I have one more question. I have to create same panel multiple times , based
on user output into the form and i have list of panel data model object
inside my form data object. Is it better to generate panels in page class
and then passed list of panels into form constructor and use ListView or
generate it inside form with RepeatingView and create new instance of
PanelData in Cycle and setting it on Panel and saving it to list like
this...

RepeatingView rp = new RepeatingView();
for(int i =0; i< n; i++){
   WebMarkupContainer parent = new WebMarkupContainer(rp.newChildID());

}

2010/10/22 Jeremy Thomerson <je...@wickettraining.com>

> On Fri, Oct 22, 2010 at 11:38 AM, Sven Meier <sv...@meiers.net> wrote:
>
> > Hi Jan,
> >
> > when are data2 and data3 initialized? They seems to be null when you put
> up
> > your models.
> >
> > Most of the time it's a bad idea to pull something out of a model and put
> > it back into another model.
> > Do this instead:
> >
> >    this.add(new MyPanel(id2, new PropertyModel(model, "data2")));
> >
> > Then in MyPanel:
> >
> >    public MyPanel(id, model){
> >         super(id, new CompoundPropertyModel(model));
> >
> > This has the following advantages:
> > - MyPanel's model is always in sync with the model of MyForm.
> > - MyPanel's usage of CompoundPropertyModel is hidden from the outside. If
> > MyPanel want's to utilize a CompoundPropertyModel (because it doesn't set
> > the model on its contained components), it should set it up by itself.
> >
> > HTH
> >
> > Sven
>
>
> Sven is spot-on, and this method he showed you above will absolutely save
> you some bugs down the road!
>
> Thanks Sven!!
>
> --
> Jeremy Thomerson
> http://wickettraining.com
> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>



-- 
Jan Ferko,
julyloov@gmail.com

Re: Fwd: Nested CompoundModel

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Fri, Oct 22, 2010 at 11:38 AM, Sven Meier <sv...@meiers.net> wrote:

> Hi Jan,
>
> when are data2 and data3 initialized? They seems to be null when you put up
> your models.
>
> Most of the time it's a bad idea to pull something out of a model and put
> it back into another model.
> Do this instead:
>
>    this.add(new MyPanel(id2, new PropertyModel(model, "data2")));
>
> Then in MyPanel:
>
>    public MyPanel(id, model){
>         super(id, new CompoundPropertyModel(model));
>
> This has the following advantages:
> - MyPanel's model is always in sync with the model of MyForm.
> - MyPanel's usage of CompoundPropertyModel is hidden from the outside. If
> MyPanel want's to utilize a CompoundPropertyModel (because it doesn't set
> the model on its contained components), it should set it up by itself.
>
> HTH
>
> Sven


Sven is spot-on, and this method he showed you above will absolutely save
you some bugs down the road!

Thanks Sven!!

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*

Re: Fwd: Nested CompoundModel

Posted by Sven Meier <sv...@meiers.net>.
Hi Jan,

when are data2 and data3 initialized? They seems to be null when you put 
up your models.

Most of the time it's a bad idea to pull something out of a model and 
put it back into another model.
Do this instead:

     this.add(new MyPanel(id2, new PropertyModel(model, "data2")));

Then in MyPanel:

     public MyPanel(id, model){
          super(id, new CompoundPropertyModel(model));

This has the following advantages:
- MyPanel's model is always in sync with the model of MyForm.
- MyPanel's usage of CompoundPropertyModel is hidden from the outside. 
If MyPanel want's to utilize a CompoundPropertyModel (because it doesn't 
set the model on its contained components), it should set it up by itself.

HTH

Sven




On 10/22/2010 06:29 PM, Jan Ferko wrote:
> Hi,
>
> I am doing on form which consists of multiple panels and data object
> hierarchy to them.
>
> For example:
>
> class Data1 {
>     Data2 data2;
> }
>
> class Data2 {
>     Data3 data3;
> }
>
> class Data3 {
>     String str;
> }
>
>
> class MyForm extends Form{
>     public MyForm(id, model){
>         super(id, model);
>         this.add(new MyPanel(id2, new
> CompoundPropertyModel(this.getModelObject().getData2());
>     }
> }
>
> and very simillar in MyPanel with data3 object, but...
>
> I have problem with updating my data model wicket always throw
> WickedMessage:
>
> Attempted to set property value on a null object.
>
> Do anyone know how to solve this?
>
> Thanks for help
> Jan Ferko
>
>    


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