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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org