Cheap chaining of compound property model to propertymodel

2011-01-31 Thread Brown, Berlin [GCG-PFS]
In this code, do you think I am using the method
CompoundPropertyModel.bind properly?  See my example in Code2, below.
In my snippet Code1, the values for the propertymodel were lost when I
did an ajax onClick.
 
But in Code2, the values are retained...
 
 
Code1:
 
 
Panel {
   Panel() {  
  CompoundPropertyModel compoundPropertyModel = new
CompoundPropertyModel(someObject);
  Form f = new Form(compoundPropertyModel);
   
  f.add(new TextField(name));   This works fine, data able to
setObject and getObject on ajax and other cases
 
  f.add(new TextField(name, new PropertyModel(someObject); --- ON
AJAX, VALUES LOST
 
  f.add(new AjaxLink() {
  onClick() { 
 target.add(form);
 }
  }

   }
}
 
...
...
 
Code2:
As a fix, I did the following:
 

final PropertyModel pm = new
PropertyModel(compoundPropertyModel, number) {
@Override
public Object getObject() {
return ((CompoundPropertyModel)
form.getDefaultModel()).bind(number).getObject();
}

public void setObject(final Object obj) {
((CompoundPropertyModel)
billingForm.getDefaultModel()).bind(number).setObject(obj);
}
};

  f.add(new TextField(name));   This works fine, data able to
setObject and getObject on ajax and other cases
 
  f.add(new TextField(name, pm)--- ON AJAX, NOW VALUES ARE
AVAILABLE, FIXED!

 
 
Berlin Brown
 


Re: Cheap chaining of compound property model to propertymodel

2011-01-31 Thread Pedro Santos
Two possible problems:

- duplicated instances, then you set some property at instance 1 expecting
to see it changed at instance 2
- missing Component#modelChanged, since you need to signal the form
component that you have set some property into its model

the best would be you send a quickstart showing the problem

On Mon, Jan 31, 2011 at 1:01 PM, Brown, Berlin [GCG-PFS] 
berlin.br...@primerica.com wrote:

 In this code, do you think I am using the method
 CompoundPropertyModel.bind properly?  See my example in Code2, below.
 In my snippet Code1, the values for the propertymodel were lost when I
 did an ajax onClick.

 But in Code2, the values are retained...


 Code1:


 Panel {
   Panel() {
  CompoundPropertyModel compoundPropertyModel = new
 CompoundPropertyModel(someObject);
  Form f = new Form(compoundPropertyModel);

  f.add(new TextField(name));   This works fine, data able to
 setObject and getObject on ajax and other cases

  f.add(new TextField(name, new PropertyModel(someObject); --- ON
 AJAX, VALUES LOST

  f.add(new AjaxLink() {
  onClick() {
 target.add(form);
 }
  }

   }
 }

 ...
 ...

 Code2:
 As a fix, I did the following:


final PropertyModel pm = new
 PropertyModel(compoundPropertyModel, number) {
@Override
public Object getObject() {
return ((CompoundPropertyModel)
 form.getDefaultModel()).bind(number).getObject();
}

public void setObject(final Object obj) {
((CompoundPropertyModel)
 billingForm.getDefaultModel()).bind(number).setObject(obj);
}
};

  f.add(new TextField(name));   This works fine, data able to
 setObject and getObject on ajax and other cases

  f.add(new TextField(name, pm)--- ON AJAX, NOW VALUES ARE
 AVAILABLE, FIXED!



 Berlin Brown




-- 
Pedro Henrique Oliveira dos Santos