You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mansour Al Akeel <ma...@gmail.com> on 2010/07/11 05:54:06 UTC

Panel update with Ajax

I have a panel that displays a product info :

public class ProductDetails extends Panel {
	private IModel<Product> model;
	public ProductDetails(String id, Product product) {
		super(id);
		setOutputMarkupId(true);
		this.setCurrentProduct(product);
		
		add(new Label("id", new PropertyModel<String>(model, "id")));

		add(new Label("codProduct", new PropertyModel<String>(this.model,
				"codProduct")));

		add(new Label("tpVat", new PropertyModel<String>(this.model, "tpVat")));
	}

	public void setCurrentProduct(Product product) {
		this.model = new CompoundPropertyModel<Product>(product);
	}
}

I am trying to update it from a link in another panel:

	AjaxLink<String> link = new AjaxLink<String>("link") {
					{
						add(new Label("id", new PropertyModel<String>(model,
								"id")));
					}
					@Override
					public void onClick(AjaxRequestTarget target) {
						Product product = item.getModelObject();
						productDetails.setCurrentProduct(product);
						target.addComponent(productDetails);
						System.out.println(target.toString());
					}
				};
				item.add(link);


Updates are not shown. I believe the issue is with the Model I am
using (IModel<Product>). However, I don't know the alternative model I
should be using (if it's a model issue).
Product is a JPA entity.
Any ideas ? example ?

thanx

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


Re: Panel update with Ajax

Posted by "robert.mcguinness" <ro...@gmail.com>.
couple of suggestions:


check the ajax response using the wicket debugger on the client side and see
what it returns
 is the panel hidden during page render?  maybe setting
setOutputMarkupPlaceholderTag(true) will help.  if you are panel swapping
then try using Panel.replaceWith(new Panel())
make sure you detach the model that is tied to the ProductDetails.  I try to
pass models across components instead of objects and let Wicket handle the
detaching.



-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Panel-update-with-Ajax-tp2284929p2285251.html
Sent from the Wicket - User mailing list archive at Nabble.com.

Re: Panel update with Ajax

Posted by Mansour Al Akeel <ma...@gmail.com>.
Sven, thank you.
But what about the ajax part.

On Tue, Jul 13, 2010 at 7:28 PM, Sven Meier <sv...@meiers.net> wrote:
> Hi,
>
> always when working with PropertyModel make sure that the properties exists.
> In your case it should probably be:
>
>    new PropertyModel<String>(this, "model.object.id"))

This one is not working as expected.
Do you have a ling for an example  ?

>
> Note that using the CompoundPropertyModel as suggested earlier is much
> easier.
>
> Regards
>
> Sven
>
> On 07/13/2010 05:16 AM, Mansour Al Akeel wrote:
>>
>> Thank you. I didn't know that wicket will pick the properties without
>> getters. I thought I have to create a getter for each property before
>> it's seen. Now the remaining issues:
>> When I use soemthing like :
>>                add(new Label("id", new PropertyModel<String>(this,
>> "model.id")));
>> I get an exception:
>>
>> WicketMessage: No get method defined for class: class
>> org.apache.wicket.model.CompoundPropertyModel expression: id
>>
>> Root cause:
>>
>> org.apache.wicket.WicketRuntimeException: No get method defined for
>> class: class org.apache.wicket.model.CompoundPropertyModel expression:
>> id
>> at
>> org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:445)
>>
>> The second issue is when I use
>> add(new AjaxEditableLabel<String>("codProduct"));
>> and then try to update the panel, I get this exception:
>> WicketMessage: No get method defined for class: class
>> rentals.entities.Product expression: label
>>
>> Root cause:
>>
>> org.apache.wicket.WicketRuntimeException: No get method defined for
>> class: class rentals.entities.Product expression: label
>> at
>> org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:445)
>>
>> Any explanation why this is happening ?
>>
>> ---------------------------------------------------------------------
>> 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: Panel update with Ajax

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

always when working with PropertyModel make sure that the properties exists.
In your case it should probably be:

     new PropertyModel<String>(this, "model.object.id"))

Note that using the CompoundPropertyModel as suggested earlier is much 
easier.

Regards

Sven

On 07/13/2010 05:16 AM, Mansour Al Akeel wrote:
> Thank you. I didn't know that wicket will pick the properties without
> getters. I thought I have to create a getter for each property before
> it's seen. Now the remaining issues:
> When I use soemthing like :
> 		add(new Label("id", new PropertyModel<String>(this, "model.id")));
> I get an exception:
>
> WicketMessage: No get method defined for class: class
> org.apache.wicket.model.CompoundPropertyModel expression: id
>
> Root cause:
>
> org.apache.wicket.WicketRuntimeException: No get method defined for
> class: class org.apache.wicket.model.CompoundPropertyModel expression:
> id
> at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:445)
>
> The second issue is when I use
> add(new AjaxEditableLabel<String>("codProduct"));
> and then try to update the panel, I get this exception:
> WicketMessage: No get method defined for class: class
> rentals.entities.Product expression: label
>
> Root cause:
>
> org.apache.wicket.WicketRuntimeException: No get method defined for
> class: class rentals.entities.Product expression: label
> at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:445)
>
> Any explanation why this is happening ?
>
> ---------------------------------------------------------------------
> 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: Panel update with Ajax

Posted by Mansour Al Akeel <ma...@gmail.com>.
Thank you. I didn't know that wicket will pick the properties without
getters. I thought I have to create a getter for each property before
it's seen. Now the remaining issues:
When I use soemthing like :
		add(new Label("id", new PropertyModel<String>(this, "model.id")));
I get an exception:

WicketMessage: No get method defined for class: class
org.apache.wicket.model.CompoundPropertyModel expression: id

Root cause:

org.apache.wicket.WicketRuntimeException: No get method defined for
class: class org.apache.wicket.model.CompoundPropertyModel expression:
id
at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:445)

The second issue is when I use
add(new AjaxEditableLabel<String>("codProduct"));
and then try to update the panel, I get this exception:
WicketMessage: No get method defined for class: class
rentals.entities.Product expression: label

Root cause:

org.apache.wicket.WicketRuntimeException: No get method defined for
class: class rentals.entities.Product expression: label
at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:445)

Any explanation why this is happening ?

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


Re: Panel update with Ajax

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

 > When I use "this", the component class should provide the properties.
 > This part I don't understand.

PropertyModel doesn't care which object holds the property. In your code 
the ProductDetails panel has a property "model", that's all.

Sven

Am 12.07.2010 14:16, schrieb Mansour Al Akeel:
> Thank you. It worked. But I am missing something. see the comments please.
>
>
> On Sun, Jul 11, 2010 at 6:35 PM, Sven Meier<sv...@meiers.net>  wrote:
>> Hi,
>>
>> a usual error when working with models:
>>
>>     new PropertyModel<String>(model, "id")
>>
>> Note you're passing around a reference to the initial model. Later updates
>> of this member will not change any other
>> reference held anywhere else. You'd have to do it this way instead:
>>
>>         add(new Label("id", new PropertyModel<String>(this, "model.id")));
>>
>
> When I use "this", the component class should provide the properties.
> This part I don't understand.
> I read the wiki about models, but still missing something.
>
>
>> But since you're using a CompoundPropertyModel already, why not let is do
>> the heavy lifting?
>>
>> public class ProductDetails extends Panel {
>>         public ProductDetails(String id, Product product) {
>>                 super(id);
>>                 setOutputMarkupId(true);
>>                 this.setCurrentProduct(product);
>>
>>                 add(new Label("id"));
>>
>>                 add(new Label("codProduct"));
>>
>>                 add(new Label("tpVat"));
>>         }
>>
>>         public void setCurrentProduct(Product product) {
>>                 setDefaultModel(new CompoundPropertyModel<Product>(product));
>>         }
>> }
>>
>>
>> HTH
>>
>> Sven
>>
>>
>> On 07/11/2010 05:54 AM, Mansour Al Akeel wrote:
>>>
>>> I have a panel that displays a product info :
>>>
>>> public class ProductDetails extends Panel {
>>>         private IModel<Product>    model;
>>>         public ProductDetails(String id, Product product) {
>>>                 super(id);
>>>                 setOutputMarkupId(true);
>>>                 this.setCurrentProduct(product);
>>>
>>>                 add(new Label("id", new PropertyModel<String>(model,
>>> "id")));
>>>
>>>                 add(new Label("codProduct", new
>>> PropertyModel<String>(this.model,
>>>                                 "codProduct")));
>>>
>>>                 add(new Label("tpVat", new
>>> PropertyModel<String>(this.model, "tpVat")));
>>>         }
>>>
>>>         public void setCurrentProduct(Product product) {
>>>                 this.model = new CompoundPropertyModel<Product>(product);
>>>         }
>>> }
>>>
>>> I am trying to update it from a link in another panel:
>>>
>>>         AjaxLink<String>    link = new AjaxLink<String>("link") {
>>>                                         {
>>>                                                 add(new Label("id", new
>>> PropertyModel<String>(model,
>>>                                                                 "id")));
>>>                                         }
>>>                                         @Override
>>>                                         public void
>>> onClick(AjaxRequestTarget target) {
>>>                                                 Product product =
>>> item.getModelObject();
>>>
>>>   productDetails.setCurrentProduct(product);
>>>
>>>   target.addComponent(productDetails);
>>>
>>>   System.out.println(target.toString());
>>>                                         }
>>>                                 };
>>>                                 item.add(link);
>>>
>>>
>>> Updates are not shown. I believe the issue is with the Model I am
>>> using (IModel<Product>). However, I don't know the alternative model I
>>> should be using (if it's a model issue).
>>> Product is a JPA entity.
>>> Any ideas ? example ?
>>>
>>> thanx
>>>
>>> ---------------------------------------------------------------------
>>> 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: Panel update with Ajax

Posted by Mansour Al Akeel <ma...@gmail.com>.
Thank you. It worked. But I am missing something. see the comments please.


On Sun, Jul 11, 2010 at 6:35 PM, Sven Meier <sv...@meiers.net> wrote:
> Hi,
>
> a usual error when working with models:
>
>    new PropertyModel<String>(model, "id")
>
> Note you're passing around a reference to the initial model. Later updates
> of this member will not change any other
> reference held anywhere else. You'd have to do it this way instead:
>
>        add(new Label("id", new PropertyModel<String>(this, "model.id")));
>

When I use "this", the component class should provide the properties.
This part I don't understand.
I read the wiki about models, but still missing something.


> But since you're using a CompoundPropertyModel already, why not let is do
> the heavy lifting?
>
> public class ProductDetails extends Panel {
>        public ProductDetails(String id, Product product) {
>                super(id);
>                setOutputMarkupId(true);
>                this.setCurrentProduct(product);
>
>                add(new Label("id"));
>
>                add(new Label("codProduct"));
>
>                add(new Label("tpVat"));
>        }
>
>        public void setCurrentProduct(Product product) {
>                setDefaultModel(new CompoundPropertyModel<Product>(product));
>        }
> }
>
>
> HTH
>
> Sven
>
>
> On 07/11/2010 05:54 AM, Mansour Al Akeel wrote:
>>
>> I have a panel that displays a product info :
>>
>> public class ProductDetails extends Panel {
>>        private IModel<Product>  model;
>>        public ProductDetails(String id, Product product) {
>>                super(id);
>>                setOutputMarkupId(true);
>>                this.setCurrentProduct(product);
>>
>>                add(new Label("id", new PropertyModel<String>(model,
>> "id")));
>>
>>                add(new Label("codProduct", new
>> PropertyModel<String>(this.model,
>>                                "codProduct")));
>>
>>                add(new Label("tpVat", new
>> PropertyModel<String>(this.model, "tpVat")));
>>        }
>>
>>        public void setCurrentProduct(Product product) {
>>                this.model = new CompoundPropertyModel<Product>(product);
>>        }
>> }
>>
>> I am trying to update it from a link in another panel:
>>
>>        AjaxLink<String>  link = new AjaxLink<String>("link") {
>>                                        {
>>                                                add(new Label("id", new
>> PropertyModel<String>(model,
>>                                                                "id")));
>>                                        }
>>                                        @Override
>>                                        public void
>> onClick(AjaxRequestTarget target) {
>>                                                Product product =
>> item.getModelObject();
>>
>>  productDetails.setCurrentProduct(product);
>>
>>  target.addComponent(productDetails);
>>
>>  System.out.println(target.toString());
>>                                        }
>>                                };
>>                                item.add(link);
>>
>>
>> Updates are not shown. I believe the issue is with the Model I am
>> using (IModel<Product>). However, I don't know the alternative model I
>> should be using (if it's a model issue).
>> Product is a JPA entity.
>> Any ideas ? example ?
>>
>> thanx
>>
>> ---------------------------------------------------------------------
>> 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: Panel update with Ajax

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

a usual error when working with models:

     new PropertyModel<String>(model, "id")

Note you're passing around a reference to the initial model. Later 
updates of this member will not change any other
reference held anywhere else. You'd have to do it this way instead:

	add(new Label("id", new PropertyModel<String>(this, "model.id")));

But since you're using a CompoundPropertyModel already, why not let is 
do the heavy lifting?

public class ProductDetails extends Panel {
	public ProductDetails(String id, Product product) {
		super(id);
		setOutputMarkupId(true);
		this.setCurrentProduct(product);
		
		add(new Label("id"));

		add(new Label("codProduct"));

		add(new Label("tpVat"));
	}

	public void setCurrentProduct(Product product) {
		setDefaultModel(new CompoundPropertyModel<Product>(product));
	}
}


HTH

Sven


On 07/11/2010 05:54 AM, Mansour Al Akeel wrote:
> I have a panel that displays a product info :
>
> public class ProductDetails extends Panel {
> 	private IModel<Product>  model;
> 	public ProductDetails(String id, Product product) {
> 		super(id);
> 		setOutputMarkupId(true);
> 		this.setCurrentProduct(product);
> 		
> 		add(new Label("id", new PropertyModel<String>(model, "id")));
>
> 		add(new Label("codProduct", new PropertyModel<String>(this.model,
> 				"codProduct")));
>
> 		add(new Label("tpVat", new PropertyModel<String>(this.model, "tpVat")));
> 	}
>
> 	public void setCurrentProduct(Product product) {
> 		this.model = new CompoundPropertyModel<Product>(product);
> 	}
> }
>
> I am trying to update it from a link in another panel:
>
> 	AjaxLink<String>  link = new AjaxLink<String>("link") {
> 					{
> 						add(new Label("id", new PropertyModel<String>(model,
> 								"id")));
> 					}
> 					@Override
> 					public void onClick(AjaxRequestTarget target) {
> 						Product product = item.getModelObject();
> 						productDetails.setCurrentProduct(product);
> 						target.addComponent(productDetails);
> 						System.out.println(target.toString());
> 					}
> 				};
> 				item.add(link);
>
>
> Updates are not shown. I believe the issue is with the Model I am
> using (IModel<Product>). However, I don't know the alternative model I
> should be using (if it's a model issue).
> Product is a JPA entity.
> Any ideas ? example ?
>
> thanx
>
> ---------------------------------------------------------------------
> 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