You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Wayne W <wa...@gmail.com> on 2012/01/11 08:01:44 UTC

Model problem with my own component

Hello,

I cannot get my component model to update correctly when being set. I
have list of products and when I click on the name via ajax I update a
Product panel to display the info. In that panel I have my component
that displays the image of the product. sudo code:

ProductPanel(id, IModel<Product> model) {
  super(id, new CompoundPropertyModel(model));

  add(new Label("name");
  add(new ProductImage("image", getDefaultModel());
}

ProductImage extends Image {
  ProductImage(id, IModel<Product> model) {
    super( id, model);

   Product p = getDefaultModelObject();
   // p always null

}


AjaxLink() {
  onclick(target) {
    productPanel.setDefaultModel(getModel());
    target.add(productPanel);
}}


When I click on the link the name is updated and displayed correctly.
However in the ProductImage component the product is always null. I
thought when setting the default model all the children are visited
and model updated.? I;ve tried debugging but get cannot figure it out.

Any ideas?

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


Re: Model problem with my own component

Posted by Wayne W <wa...@gmail.com>.
thanks Sven

On Wed, Jan 11, 2012 at 6:46 PM, Sven Meier <sv...@meiers.net> wrote:
> Hi,
>
>
>> add(new ProductImage("image", getDefaultModel());
>
> this line is causing the null product.
>
>
>> I thought when setting the default model all the children are visited and
>> model updated.?
>
> No, not at all. Either you have to do that by yourself or you have to give
> ProductImage a more intelligent model:
>
>     add(new ProductImage("image", new AbstractReadOnlyModel<Product>() {
>          public Product getObject() {
>              return getDefaultModel().getObject();
>          }
>     });
>
> Hope this helps
> Sven
>
> Am 11.01.2012 08:01, schrieb Wayne W:
>>
>> Hello,
>>
>> I cannot get my component model to update correctly when being set. I
>> have list of products and when I click on the name via ajax I update a
>> Product panel to display the info. In that panel I have my component
>> that displays the image of the product. sudo code:
>>
>> ProductPanel(id, IModel<Product>  model) {
>>   super(id, new CompoundPropertyModel(model));
>>
>>   add(new Label("name");
>>   add(new ProductImage("image", getDefaultModel());
>> }
>>
>> ProductImage extends Image {
>>   ProductImage(id, IModel<Product>  model) {
>>     super( id, model);
>>
>>    Product p = getDefaultModelObject();
>>    // p always null
>>
>> }
>>
>>
>> AjaxLink() {
>>   onclick(target) {
>>     productPanel.setDefaultModel(getModel());
>>     target.add(productPanel);
>> }}
>>
>>
>> When I click on the link the name is updated and displayed correctly.
>> However in the ProductImage component the product is always null. I
>> thought when setting the default model all the children are visited
>> and model updated.? I;ve tried debugging but get cannot figure it out.
>>
>> Any ideas?
>>
>> ---------------------------------------------------------------------
>> 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
>

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


Re: Model problem with my own component

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

 > add(new ProductImage("image", getDefaultModel());

this line is causing the null product.

 > I thought when setting the default model all the children are visited 
and model updated.?

No, not at all. Either you have to do that by yourself or you have to 
give ProductImage a more intelligent model:

      add(new ProductImage("image", new AbstractReadOnlyModel<Product>() {
           public Product getObject() {
               return getDefaultModel().getObject();
           }
      });

Hope this helps
Sven

Am 11.01.2012 08:01, schrieb Wayne W:
> Hello,
>
> I cannot get my component model to update correctly when being set. I
> have list of products and when I click on the name via ajax I update a
> Product panel to display the info. In that panel I have my component
> that displays the image of the product. sudo code:
>
> ProductPanel(id, IModel<Product>  model) {
>    super(id, new CompoundPropertyModel(model));
>
>    add(new Label("name");
>    add(new ProductImage("image", getDefaultModel());
> }
>
> ProductImage extends Image {
>    ProductImage(id, IModel<Product>  model) {
>      super( id, model);
>
>     Product p = getDefaultModelObject();
>     // p always null
>
> }
>
>
> AjaxLink() {
>    onclick(target) {
>      productPanel.setDefaultModel(getModel());
>      target.add(productPanel);
> }}
>
>
> When I click on the link the name is updated and displayed correctly.
> However in the ProductImage component the product is always null. I
> thought when setting the default model all the children are visited
> and model updated.? I;ve tried debugging but get cannot figure it out.
>
> Any ideas?
>
> ---------------------------------------------------------------------
> 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