Thank you. It worked. But I am missing something. see the comments please.
On Sun, Jul 11, 2010 at 6:35 PM, Sven Meier <[email protected]> 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: [email protected] >> For additional commands, e-mail: [email protected] >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
