Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: PropertyReference class mentioned in the code example has been changed to PropertyModel (which is suppose author meant)

...

My problem was that I created a label with constant model, that is set to the value of currentItem.getName. So even if you change current item later, the item container is not recreated, thus the label still shows old current item name.

The solution would be to create the label like this (assuming currentItem is a member variable of enclosing class):

Code Block
public class MyPage extends WebPage {
  private MyObject object;

  public MyObject getObject() {
    return object;
  }

  public void setObject(MyObject object) {
    this.object = object;
  }

  public class MyObjectDetailsContainer extends WebMarkupContainer {
    public MyObjectDetailsContainer(String id) {
      add(new Label("objectName", new PropertyReferencePropertyModel(MyPage.this, "object.name"));
    }
  }
}