final ContainerModelTestPage page = new ContainerModelTestPage();
TestLoadableDetachableObjectModel nestedModel = new TestLoadableDetachableObjectModel();
BeanMetaData meta = new BeanMetaData(nestedModel.getObject().getClass(), null, page, null, false);
BeanForm form = new BeanForm("beanForm", nestedModel, meta);
page.add(form);
tester.startPage(new ITestPageSource() {
private static final long serialVersionUID = 1L;
public Page getTestPage()
{
return page;
}
});
//tester.debugComponentTrees();
// Check elements, labels.
String firstRowPath = "beanForm:f:tabs:r:0";
String namePath = firstRowPath + ":c:0:c";
String nameFieldPath = namePath + ":c";
tester.assertLabel(namePath + ":l", "Name");
tester.assertComponent(nameFieldPath, InputField.class);
Component nameField = tester.getComponentFromLastRenderedPage(nameFieldPath);
String serialNumPath = firstRowPath + ":c:1:c";
String serialNumFieldPath = serialNumPath + ":c";
tester.assertLabel(serialNumPath + ":l", "Serial Number");
tester.assertComponent(serialNumFieldPath, InputField.class);
Component serialNumField = tester.getComponentFromLastRenderedPage(serialNumFieldPath);
// Check attaching/detaching component's model (BeanPropertyModel).
BeanPropertyModel nameFieldModel = (BeanPropertyModel) nameField.getDefaultModel();
assertFalse(nestedModel.isAttached());
// Should attach the nested model's object.
nameFieldModel.getObject();
assertTrue(nestedModel.isAttached());
NonSerializableBean firstBean = (NonSerializableBean)nestedModel.getObject();
// Make the first bean detach. This also tests that the model is attached somewhere below the page.
//page.detachModels(); // TODO 1.3 doesn't work
detachModels(page);
assertFalse(nestedModel.isAttached());
NonSerializableBean secondBean = (NonSerializableBean)nestedModel.getObject();
// Should be different and attached now.
assertNotSame(firstBean, secondBean);
assertTrue(nestedModel.isAttached());
// Assert PropertyChangeListener on BeanForm is called.
assertFalse( form.isComponentRefreshNeeded() );
nameFieldModel.setObject("test");
assertTrue( form.isComponentRefreshNeeded() );
// Clear the refresh components.
form.clearRefreshComponents();
// Assert PropertyChangeListener on BeanForm is called after detach()/attach().
//page.detachModels(); // TODO 1.3 doesn't work
detachModels(page);
assertFalse(nestedModel.isAttached());
assertFalse( form.isComponentRefreshNeeded() );
nameFieldModel.setObject("test");
assertTrue( form.isComponentRefreshNeeded() );
// Clear the refresh components.
form.clearRefreshComponents();
}