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.

empty SQLContainer form

Hugo Hanisch
9 years ago Jun 22, 2012 8:20pm
Hugo Hanisch
9 years ago Jun 30, 2012 8:52pm
Jens Jansson
9 years ago Jul 01, 2012 9:23am
Hugo Hanisch
9 years ago Jul 10, 2012 6:48am
Henri Sara
9 years ago Jul 11, 2012 6:10am

SQLContainer.addItem() creates an item with a temporary id (and then stores it if autocommit is on), if storing it later it gets the next id from the DB sequence or such.
Take note of its return value, get the item from the container with getItem(Object) and modify and save it when you want.

Hugo Hanisch
9 years ago Jul 26, 2012 12:36am

Henri Sara: SQLContainer.addItem() creates an item with a temporary id (and then stores it if autocommit is on), if storing it later it gets the next id from the DB sequence or such.
Take note of its return value, get the item from the container with getItem(Object) and modify and save it when you want.

Thank you for your answer Henri.....

I'm trying this:

Object a = container.addItem();
form.setItemDataSource(container.getItem(a));
addComponent(form);

and it shows only the form footer buttons, since the properties of that item have no value at all....

so I tryed also this:

Object a = container.addItem();
Collection<?> properties = ((Item) a).getItemPropertyIds();
Iterator itr = properties.iterator();
while(itr.hasNext()){	
	container.getItem(a).getItemProperty(itr.next()).setValue(null);
}
form.setItemDataSource(container.getItem(a));
addComponent(form);

and I get a class cast exception: com.vaadin.data.util.sqlcontainer.TemporaryRowId cannot be cast to com.vaadin.data.Item....

any idea on how should I do this?

regards, and thank you very much....

Hugo

Henri Sara
9 years ago Jul 26, 2012 6:28am

The first code snippet was handling the ID correctly, the second isn't. See the bolded part below for a correction.

Object a = container.addItem();
Collection<?> properties = [b]container.getItem(a)[/b].getItemPropertyIds();
Iterator itr = properties.iterator();
while(itr.hasNext()){	
	container.getItem(a).getItemProperty(itr.next()).setValue(null);
}
form.setItemDataSource(container.getItem(a));
addComponent(form);

You'll probably want to use a temporary variable for container.getItem(a) to avoid calling it many times unnecessarily.

Last updated on Jul, 26th 2012
Hugo Hanisch
9 years ago Jul 26, 2012 2:07pm
Henri Sara
9 years ago Jul 27, 2012 5:57am

Hugo H Hanisch: ...what I'm trying to do now is that the fields come with no value in them instead of null....

Text fields? If you cannot do this with default values, use a FormFieldFactory and call setNullRepresentation("") on the text fields.

Hugo Hanisch
9 years ago Jul 27, 2012 6:18am