Author: mgrigorov Date: Sun Feb 13 11:02:08 2011 New Revision: 1070210 URL: http://svn.apache.org/viewvc?rev=1070210&view=rev Log: WICKET-3413 FLAG_INHERITABLE_MODEL and default model change
reset 'inherited model' flag if model changed and a new one is not IComponentInheritedModel Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/model/InheritedModelTest.java Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java?rev=1070210&r1=1070209&r2=1070210&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java (original) +++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/Component.java Sun Feb 13 11:02:08 2011 @@ -2956,6 +2956,12 @@ public abstract class Component if (model != null) { data_set(0, model); + // WICKET-3413 reset 'inherited model' flag if model changed + // and a new one is not IComponentInheritedModel + if (getFlag(FLAG_INHERITABLE_MODEL) && !(model instanceof IComponentInheritedModel)) + { + setFlag(FLAG_INHERITABLE_MODEL, false); + } } else { Modified: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/model/InheritedModelTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/model/InheritedModelTest.java?rev=1070210&r1=1070209&r2=1070210&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/model/InheritedModelTest.java (original) +++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/model/InheritedModelTest.java Sun Feb 13 11:02:08 2011 @@ -73,4 +73,31 @@ public class InheritedModelTest extends data2.put("label", "foo"); assertEquals("foo", label.getDefaultModelObject()); } + + /** + * Tests if Component#FLAG_INHERITABLE_MODEL reset after model change (WICKET-3413). + */ + public void testResetInheritedModelFlag() + { + ValueMap data1 = new ValueMap(); + data1.put("label", "foo"); + + ValueMap data2 = new ValueMap(); + data2.put("value", "bar"); + + InheritedTestPage page = new InheritedTestPage(); + + page.setDefaultModel(new CompoundPropertyModel(data1)); + tester.startPage(page); + assertEquals("foo", page.label.getDefaultModelObject()); + + page.label.setDefaultModel(new PropertyModel(data2, "value")); + tester.startPage(page); + assertEquals("bar", page.label.getDefaultModelObject()); + + page.detach(); + + tester.startPage(page); + assertEquals("bar", page.label.getDefaultModelObject()); + } }