Change item in BeanItemContainer

Hi together,

I stuck in problems changing items in my BeanItemContainer. The container is the datasource of my grid and the container is filled with a list. Now I want to change a row in my grid. To do this, I’m trying to change an item in the list or in the container but I dont know how. Whenever I change an item in the list, I get java.lang.NullPointerException.

Some code:

List<Kontrakt> kontrakte = Arrays.asList(
          new Kontrakt[]{
              //added some stuff

BeanItemContainer<Kontrakt> container =
                new BeanItemContainer<Kontrakt>(Kontrakt.class);



I know that I could remove the item from the container, change it and add it again. But then the “new” row is always at the bottom of the list and I don’t want to change the order by changing an item.

Thanks for your great help

Can you post the stack trace?
Have you implemented equals and hashcode on Kontrakt class?

Yes I’ve implemented hascode and equals on Kontrakt class.
Is my way to change the list item even the right way to edit the row?

Jun 06, 2016 12:37:01 PM com.vaadin.server.DefaultErrorHandler doDefault
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.vaadin.server.VaadinSession$FutureAccess.get(
at com.vaadin.server.VaadinService.runPendingAccessTasks(
at com.vaadin.server.VaadinSession.unlock(
at com.vaadin.server.VaadinService.ensureAccessQueuePurged(
at com.vaadin.server.VaadinService.accessSession(
at com.vaadin.server.VaadinSession.access(
at com.vaadin.ui.UI.access(
at frontend.thesis.webapp.Fenster$
at java.util.TimerThread.mainLoop(Unknown Source)
at Source)
Caused by: java.lang.NullPointerException
at frontend.thesis.webapp.Fenster$4.lambda$0(
at com.vaadin.ui.UI.accessSynchronously(
at com.vaadin.ui.UI$
at java.util.concurrent.Executors$ Source)
at Source)
at com.vaadin.server.VaadinService.runPendingAccessTasks(
… 8 more

It could be better update the item using the container property directly, so value change events are fired

container.getContainerProperty(kontrakte.get(0), "name").setValue("example"); Can you post the whole Fenster class?

I tried the container property you have provided with this error:

Jun 06, 2016 1:11:05 PM com.vaadin.server.DefaultErrorHandler doDefault
at com.vaadin.ui.Grid$RowDataGenerator.writeData(
at com.vaadin.ui.Grid$RowDataGenerator.generateData(
at com.vaadin.server.communication.UidlWriter.write(
at com.vaadin.server.communication.AtmospherePushConnection.push(
at com.vaadin.server.communication.PushHandler$
at com.vaadin.server.communication.PushHandler.callWithUi(
at com.vaadin.server.communication.PushHandler.onMessage(
at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(
at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(
at org.atmosphere.cpr.AsynchronousProcessor.action(
at org.atmosphere.cpr.AsynchronousProcessor.suspended(
at org.atmosphere.container.Servlet30CometSupport.service(
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(
at org.atmosphere.websocket.DefaultWebSocketProcessor$
at org.atmosphere.util.VoidExecutorService.execute(
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(
at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(
at org.atmosphere.container.JSR356Endpoint$1.onMessage(
at org.atmosphere.container.JSR356Endpoint$1.onMessage(
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(
at org.apache.tomcat.websocket.WsFrameBase.processDataText(
at org.apache.tomcat.websocket.WsFrameBase.processData(
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at org.apache.tomcat.util.threads.TaskThread$
at Source)

My Fenster class:[code]
public class Fenster extends Window {
Grid grid;
public Fenster() {
super(“Orderbuch”); // Set window caption

    VerticalLayout content = new VerticalLayout();
    grid = new Grid();
    List<Kontrakt> kontrakte = Arrays.asList(
            new Kontrakt[]{
                    new Kontrakt("item",1),
                    new Kontrakt("item2",2)
    BeanItemContainer<Kontrakt> container =
            new BeanItemContainer<Kontrakt2>(Kontrakt.class);
    container.getContainerProperty(kontrakte.get(0), "name").setValue("example");


It works for me; I’m able to reproduce your last error only if I add mutable
property in the equals implementation of Kontrakt

I’m not sure what you mean. I generated the equals and the part with
looks like this:

if (name == null) {
            if ( != null)
                return false;
        } else if (!name.equals(
            return false;

Sorry, in my previous answer I wrote “equals implementation” but I meant “hashcode implementation”.

If your hashcode implementation is based on the mutable field
then the BeanItemContainer could not lookup the bean from his internal
HashMap after modification as stated in

If you cannot modify the hashcode implementation you should end up wiht a remove, modify and insert operation

//container.getContainerProperty(kontrakte.get(0), "name").setValue("example");
Kontrakt kontrakt = kontrakte.get(0);
int idx = container.indexOfId(kontrakt);
container.removeItem(kontrakt); kontrakt.setName("example");
container.addItemAt(idx, kontrakt); 


I deleted my hashcode in the kontrakt class. Now I can change the name property with:

container.getContainerProperty(kontrakte.get(0), "name").setValue("example"); I added another column
to my grid and tried to change it the same way:

container.getContainerProperty(kontrakte.get(0), "bidqty").setValue(12);

​Unfortunately I get the error:

Exception in thread “Timer-6”$ReadOnlyException
at frontend.thesis.webapp.Fenster$1$
at java.util.TimerThread.mainLoop(Unknown Source)
at Source)


container.getContainerProperty(kontrakte.get(0), "bidqty").setReadOnly(false);

doens’t help to solve the error.

The first thing I can suppose is that your Kontract class does not have a public setter method

public void setBidqty(int qty) 

Was my first thought as well, but my class has

    public void setBidqty(int bidqty) {
        this.bidqty = bidqty;

Ok I solved it. It’s working now.
The setter wasn’t the problem but the getter. I returned a String and not a int because it was easier for me to display the value of the int in the table. This was my getter:

public String getBidqty() { return String.valueOf(bidqty); } I changed it to:

public int getBidqty() { return bidqty; } and now I can edit the bidqty property as well.

Thank you for your help!!

I had a similar problem, but with a ComboBox. In my case, I had to change

public void setCertificateOfCompliance( Boolean certificateOfCompliance ){ if( certificateOfCompliance instanceof Boolean ) setCertificateOfCompliance( certificateOfCompliance.toString() ); else setCertificateOfCompliance( "false" ); } in my bean to public void setCertificateOfCompliance( boolean certificateOfCompliance ){ setCertificateOfCompliance( "" + certificateOfCompliance ); } So thanks for your help - it pointed me in the right direction. My problem was almost certainly the fact that the “setCertificateOfCompliance( String value )” was getting confused with “setCertificateofCompliance( Boolean value )” by the “BeanFieldGroup.bindFieldsUnbuffered” method call.