reiern70 opened a new pull request, #1605:
URL: https://github.com/apache/wicket/pull/1605

   A component has a single model that the framework detaches at the end of 
each request. A component using further models has to detach them itself in 
onDetach(), detachModel() or detachModels(); when it forgets, a 
LoadableDetachableModel stays loaded and is serialized with the page.
   
   Component can now track additional models next to the default model:
   
   - addAdditionalModel(M) registers a model and returns it, typed as given, so 
it can be assigned in the same statement: foo = addAdditionalModel(new 
FooModel()). Registering a model twice has no effect.
   - replaceAdditionalModel(IModel, M) detaches and unregisters the previous 
model and registers the given one, unless both are the same, and returns the 
given model; it is meant for setters.
   - removeAdditionalModel(M) detaches, unregisters and returns a model.
   - getModels() returns the default model, if any, followed by the additional 
models, without triggering model inheritance.
   - detachModels() detaches the additional models, including the model inside 
a wrapper, as detachModel() does for the default model.
   - Component(String, IModel, IModel...) registers the given additional 
models; MarkupContainer, WebMarkupContainer, WebComponent, Panel and 
GenericPanel get the same constructor. The existing (String, IModel) 
constructors stay; a (String, IModel...) overload was avoided because it would 
make new X("id", null) ambiguous.
   
   Additional models are registered as given and not wrapped, so the methods 
can return the model itself; a component using an IComponentAssignedModel 
registers wrap(model). They are tracked without an index, so a subclass does 
not need to know which models its superclasses use.
   
   The models are kept as component meta data, which costs a component roughly 
50 to 80 bytes more than detaching the same models by hand, whatever their 
number: a meta data entry, the array holding the models, and the state holder a 
component needs once it has more than one kind of state. That is a good trade 
for a component used a few dozen times on a page and a bad one for a component 
rendered in the thousands, so the components shipped with Wicket are left as 
they are and keep detaching their models themselves. The javadoc of 
addAdditionalModel and the user guide say so, with the numbers.
   
   Detaching an IWrapModel whose wrapped model is null no longer throws.
   
   The user guide section on components with more than one model describes the 
new methods.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to