Hi,

> the setModel(CompoundPropertyModel ...) actually KEEPS the FLAG_INHERITABLE_MODEL on true

where is that?

Sven


On 07/29/2014 04:29 PM, Raoul Zander wrote:
Hi everyone,

I think there is some kind of bug in the handling of CompoundPropertyModel
(or any IComponentInheritedModel).

In Component exists a Flag FLAG_INHERITABLE_MODEL - which is set to true
whenever a model is inherited from a parent, so that the model can be
nulled onDetach. Thing is: The same flag is set when a
IComponentInheritedModel is set as default model (via setModelImpl(IModel)).

This leads to exceptions with chained CompoundPropertyModels as in the
following scenario:

(With correct indention and code high lighting: http://pastebin.com/5iu0qhWw
)

// POJOs (implements Serializable omitted)
public class Game {
     private Data data;
     // getters / setters
}

public class Data {
     private Value value;
     // getters / setters
}


public class Value {
     private int number;
     // getters / setters
}

// Panels
public class DataPanel extends GenericPanel<Data> {

     public DataPanel(String id) {
         super(id);
     }

     protected void onInitialize() {
         super.onInitialize();

         setModel(new CompoundPropertyModel<Data>(getModel()));
         add(new ValuePanel("value"));
     }
}

public class ValuePanel extends GenericPanel<Value> {

     public ValuePanel(String id) {
         super(id);
     }

     protected void onInitialize() {
         super.onInitialize();

         setModel(new CompoundPropertyModel<Value>(getModel()));
         add(new Label("number"));
     }
}

// and the page
public class GamePage extends WebPage {

     protected void onInitialize() {
         super.onInitialize();

         setDefaultModel(new CompoundPropertyModel<Game>(new Game()));
         // make Page stateful like it would happen with AJAX links and alike
         setStatelessHint(false);
         add(new DataPanel("data"));
     }
}

Markup is irrelevant. The first time the page loads correct but as soon as
you refresh the page you'll get the error "No get method defined for class:
class Game expression: number".
Why that? Because the setModel(CompoundPropertyModel ...) actually KEEPS
the FLAG_INHERITABLE_MODEL on true so that our custom set model will be
nulled on the next detach.

In my opinion this is a bug as FLAG_INHERITABLE_MODEL should be true if
(and only if) the current component model was inherited - and not if it is
*inheritable*.
But on the other hand: Maybe i'm using the models the wrong way and there's
a better way to achieve the same result (basically using
CompoundPorpertyModels on different levels of an object graph)

Kind regards,
rza



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

Reply via email to