SQLContainer-removeItem()

Hi
i have got an Item like this “Item item = getItemDataSource();”, but how can I delete it from SQLContainer by removeItem()?
Thank you very much for your replay!

You need to get the item id of the item you wish to remove. Give that item id as a parameter to the removeItem method. So, for example, if you have populated a Select component using an SQLContainer and want to remove the selected item, then call select.getValue() to get the item id of the selected item.

Hi,

I discovered that if you add an Item to a filtered SQLContainer by invocation of addItem(), one cannot remove it with removeItem()
This is because removeItem() uses containsId(Object itemId) which invokes itemPassesFilters(item)
The new Item does not pass the filter, so it cannot be removed.

EDIT: my issue was solved by calling SQLContainer.rollback();

Kind regards,
Harke

Hi:

Where do you add rollback()?

I have this and I get an error:

public void buttonClick(ClickEvent event) {
		Button boton=event.getButton();
		if (boton==deleteItem){
			container.removeItem(target);
			try {
				container.commit();
			} catch (UnsupportedOperationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

regards,

Hugo

Hi !
I’ve faced with the same problem.
I use SQLContainer to edit data in Table. The adding is good, but when i’m trying to remove item i get this

I do something like this:

  1. select row from the table
  2. get the id of this row by selectedId = managerTable.getValue();
    3)try to remove it

sqlcontainer.removeItem(selectedId);
sqlcontainer.commit();

and then get that error in commit. Row is removed from the table, but not from DB.

I use vaadin 6.8.4 and postrges
Init of container:

tableQuery = getTableQuery();
tableQuery.setVersionColumn("TLOCK");
sqlcontainer = new SQLContainer(tableQuery);
managerTable.setContainerDataSource(sqlcontainer);

I’ve already read all threads about RemoveItem and haven’t got the clear answer. Does anyone sove this problem? Thanks in advance!

Hi all,

I have a similar issue -

deleteButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Object itemId = numbersTable.getValue();
container.removeItem(itemId);
try {
container.commit();
fg.discard();
} catch (UnsupportedOperationException | SQLException e) {
e.printStackTrace();
}
}
});

As I debug, the value in itemId is correcta and container.removeItem(itemId) is also getting executed without issues. But as container.commit is executed, the following error is seen -

Caused by: java.lang.NullPointerException
at com.vaadin.data.util.sqlcontainer.query.generator.DefaultSQLGenerator.generateDeleteQuery(DefaultSQLGenerator.java:267)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.removeRow(TableQuery.java:731)
at com.vaadin.data.util.sqlcontainer.SQLContainer.commit(SQLContainer.java:1000)
at com.example.vaadinexperiments.VaadinexperimentsUI$2.buttonClick(VaadinexperimentsUI.java:125)

This looks to resolve the issue -

numbersTable.removeItem(numbersTable.getValue());

So am directlt removing the item from table component. And after this I invoke -

container.commit();

Larsen.

HI ,
I REALLY NEED TO PURCHASE A FAKE US DRIVING LICENSE