/**
* Tests BeanForm with a LoadableDetachableModel instead of a direct bean.
*/
public void testBeanFormWithLoadableDetachableModel()
{
WicketTester tester = new WicketTester();
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());