Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

MasterDetailEditor throws NullPointerException when adding new Entity

Kurt Berg
10 years ago Apr 07, 2012 4:04pm
Abimael Machado
10 years ago Apr 08, 2012 3:43am

I have the same problem. It´s occur because de method createEntity doesn´t create id for the item. The masterdetaileditor use the itemid to retrieve the item; as has null value the error occur. Look below (red line)
I have a one-to-many relationship with two tables and I don´t know yet how resolve it.

public MasterDetailEditor(FieldFactory fieldFactory,
EntityContainer<?> containerForProperty, Object itemId,
Object propertyId, Component uiContext) {
this.fieldFactory = fieldFactory;
this.containerForProperty = containerForProperty;
this.itemId = itemId;
this.propertyId = propertyId;
masterEntity = containerForProperty.getItem(itemId).getEntity();
boolean writeThrough = true;
if (uiContext instanceof Form) {
Form f = (Form) uiContext;
writeThrough = f.isWriteThrough();
}
buildContainer(writeThrough);

buildLayout();

setCaption(DefaultFieldFactory.createCaptionByPropertyId(propertyId));
}

Last updated on Apr, 8th 2012
Kurt Berg
10 years ago Apr 08, 2012 3:47pm
Sándor Kelemen
10 years ago Apr 09, 2012 12:14am
Kurt Berg
10 years ago Apr 12, 2012 6:30am
Erich Reich
9 years ago Jul 09, 2012 9:08pm
Erich Reich
9 years ago Jul 11, 2012 11:58pm

I ended up changing the MasterDetailEditor to have the EntityItem as a constructor argument instead of the itemId. This solved my problem. I've attached my class as 'PlasmaDetailEditor'. You'll also have to extend the FieldFactory slightly but that shouldn't be too difficult as the target 'Item' is already present in the createField method.

While I was in the code I also changed the table so the page length goes between 0 -> 5 (but the MAX_PAGE_LENGTH) is a final int at the top of the class. This way the table takes up as little space as possible when it is empty to conserve real estate. If you want a constant size, feel free to comment that out :P

Cheers

Last updated on Jul, 11th 2012
Mario Giammarco
7 years ago Dec 14, 2014 6:33pm