// Save component
this.component = component;
// Get component model
final IModel model = component.getModel();
// If the component has a model, it's about to change!
if (model != null)
{
// Should we clone the model?
boolean cloneModel = true;
// If the component is a form component
if (model instanceof CompoundPropertyModel)
{
if (component instanceof FormComponent)
{
// and it's using the same model as the form
if (((FormComponent)component).getForm().getModel() == model)
{
// we don't need to clone the model, because it will
// be re-initialized using initModel()
cloneModel = false;
}
}
else
{
// If the component is using the same model as the page
if (component.getPage().getModel() == model)
{
// we don't need to clone the model, because it will
// be re-initialized using initModel()
cloneModel = false;
}
}
}
// Clone model?
if (cloneModel)
{
model.detach();
originalModel = (IModel)Objects.cloneModel(model);
}
else
{
originalModel = model;