Hi,

final Label testLabel = new Label("testLabel", new
PropertyModel<String>(this, "prodNo"));

and in same class
public String getProdNo() {
 return selected.getProdNo();
}

or alternate

final Label testLabel = new Label("testLabel", new
PropertyModel<String>(this, "selected.prodNo"));

in same class
public OrfData getSelected() {
 return selected;
}

With your implementation you add a reference to selected (version1) in testModel. If you change selected to version2
your model is still referencing version1.
Another alternative is to call setObject on testModel. But then you have to make testModel a local attribute.
Selected is not required anymore as an attribute.

Kogel, Jonck-van-der schrieb:
Hi,
I ran into some strange behavior with PropertyModels vs. "regular"
models. I set up a very simple example that demonstrates what works on
the one hand and what I would expect to work as well but does not. What
I'm doing is very basic: I'm population a list and when a user clicks on
an item in the link the details of that object are shown using ajax. The
following code works fine:
public class HomePage extends WebPage {
 @SpringBean
 private OrfDataService orfDataService;
private OrfData selected = new OrfData(); public HomePage(final PageParameters parameters) { // code block to be replaced Model<String> testModel = new Model<String>() {
      public String getObject() {
       return selected.getProdNo();
      }
     };
  final Label testLabel = new Label("testLabel", testModel);
  // end of code block to be replaced
testLabel.setOutputMarkupId(true);
        add(testLabel);
add(new ListView<OrfData>("orfDataList", orfDataService.getOrfData())
{
public void populateItem(final ListItem<OrfData> listItem) {
    // add all the listItem labels etc..
listItem.add(new AjaxLink<OrfData>("selectLink") {
     @Override
public void onClick(AjaxRequestTarget target) { selected = getModelObject(); target.addComponent(testLabel);
     }
});
   }
  });
    }
public void setOrfDataService(OrfDataService orfDataService) {
  this.orfDataService = orfDataService;
 }
}

However, naturally I want to do the above using PropertyModel. But if I
replace the commented code block above with the following line:
final Label testLabel = new Label("testLabel", new
PropertyModel<String>(selected, "prodNo"));

The label no longer gets updated.
Any idea what I'm doing wrong here? Thanks, Jonck
P.S. I know the usage of the orfDataService is not really all that great
here, it's just as an example



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to