FieldFactory doesn't call the createField() methods!

I have created a Form and added a FieldFactory to it, but I cannot get output from the createField() methods at all! They are simply never called because they don’t write anything anywhere. What am I doing wrong or is there a bug somewhere in RC8?


package com.logica.medi.printingadmin;

import com.itmill.toolkit.data.Container;
import com.itmill.toolkit.data.Item;
import com.itmill.toolkit.data.Property;
import com.itmill.toolkit.ui.Component;
import com.itmill.toolkit.ui.Field;
import com.itmill.toolkit.ui.FieldFactory;
import com.itmill.toolkit.ui.Form;
import com.itmill.toolkit.ui.Panel;
import com.itmill.toolkit.ui.VerticalLayout;
import com.itmill.toolkit.ui.Window;

class TestEditor extends Window implements FieldFactory {

    private Form myForm;
    private Item editableItem = null;

    public TestEditor(Item selectedItem) {
        super("Editor");
        editableItem = selectedItem;

        // Create main layout and add it to default
        VerticalLayout main = new VerticalLayout();
        setLayout(main);
        main.setStyleName(Panel.STYLE_LIGHT);
        setVisible(true);

        // Create a new form from the Item
        myForm = new Form();
        myForm.setImmediate(true);
        myForm.setItemDataSource(editableItem);
        myForm.setFieldFactory(this);
        main.addComponent(myForm);
    }

    public Field createField(Class type, Component uiContext) {
        System.out.println("1");
        return null;
    }

    public Field createField(Property property, Component uiContext) {
        System.out.println("2");
        return null;
    }

    public Field createField(Item item, Object propertyId, Component uiContext) {
        System.out.println("3");
        return null;
    }

    public Field createField(Container container, Object itemId,
            Object propertyId, Component uiContext) {
        System.out.println("4");
        return null;
    }

}

setItemDataSource will populate the form using the current field factory so you should set the field factory before that call. The setFieldFactory method does not re-create the fields

Woot…? you mean I have to code in some logical order? I need to use my brain? :mrgreen: Thanks, I can’t believe how fast you guys are at answering these posts! :wink: