No properties in the items

I have made a custom container like this:

The EntryConnector.getEntries() fetch all entries from the database.

I have added this container to a table, and they show up as they should. The table is filled with the list of entries and they show the email and name fields.

However, when I set an item as a datasource on a form, they don’t show up at all. I tried using the sourcecode for the form in the tutorial (chapter 5 state), and the only thing I see is the footer buttons.

What am I doing wrong with the item?

Bo Thorsen,
Monty Program AB.

Hi Bo,

Welcome to forums! I am a bit unsure what is the problem as your code works for me. Here is a bit modified example:

public class EntryContainer extends IndexedContainer {
    public EntryContainer() {
        try {

            addContainerProperty(PROPERTY_NAME, String.class, null);
            addContainerProperty(PROPERTY_EMAIL, String.class, null);

            for (int i = 0; i < 100; i++) {
                Item item = addItem(new Integer(i));
                item.getItemProperty(PROPERTY_NAME).setValue("name" + i);
                item.getItemProperty(PROPERTY_EMAIL).setValue("email" + i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static final String PROPERTY_NAME = "name";
    public static final String PROPERTY_EMAIL = "email";

    public static final Object COLUMN_ORDER = new Object[] { "name", "email" };

    public static final String[] COLUMN_HEADERS = new String[]
 { "Name",
            "Email" };
}
public class BotestApplication extends Application {

    public void init() {
        Window mainWindow = new Window("Botest Application", new SplitPanel(
                SplitPanel.ORIENTATION_HORIZONTAL));
        setMainWindow(mainWindow);

        final EntryContainer e = new EntryContainer();

        final Table t = new Table();
        t.setContainerDataSource(e);
        mainWindow.addComponent(t);
        t.setImmediate(true);
        t.setSizeFull();

        final Form f = new Form();
        mainWindow.addComponent(f);

        t.setSelectable(true);
        t.addListener(new Property.ValueChangeListener() {

            public void valueChange(ValueChangeEvent event) {
                f.setItemDataSource(t.getItem(t.getValue()));

            }
        });
    }

}

  • Joonas

Hi,

This is a long shot, but: it’s fairly easy to say
form.setData()
instead of
form.setItemDataSource()
.

I did this once recently (I was really tired! ;-), and it took me a while to figure out why nothing showed up…

Best Regards,
Marc

I tracked this down now. The problem was that I did this in the form code:

public void setItemDataSource(Item newDataSource) {
	if (newDataSource != null) {
		List<Object> orderedProperties = Arrays.asList(EntryContainer.COLUMN_ORDER);
		super.setItemDataSource(newDataSource , orderedProperties);

When I removed the orderedProperties argument, my form came back as it should.

But I don’t understand why this is a problem. As you can see in the container code I originally posted, the properties are the same. Well, the strings in them are the same, the objects might not be.

Ok, it was indeed the problem. I changed the code in the container to this:

public static final String[] COLUMN_ORDER = new String[]

{ PROPERTY_NAME, PROPERTY_EMAIL };

And then it worked.