You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Brown, Berlin [GCG-PFS]" <Be...@Primerica.com> on 2011/01/31 16:01:16 UTC

Cheap chaining of compound property model to propertymodel

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

Posted by Pedro Santos <pe...@gmail.com>.
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.Brown@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