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.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
NativeSelect and SQLContainer
Hello,
I've got the following scenario: a database table "fruits" with two columns, "id" and "name". I'd like to populate a dropdown single-selection UI component with the records from this table, in order to more or less get what in plain HTML would look like:
<select>
<option value="1">Apple</option>
<option value="2">Pear</option>
<option value="3">Durian</option>
</select>
I thought that the absolutely straightforward way to do that would be use an SQLContainer with a TableQuery and then pass it to the component. It turns out however that this only works with the ComboBox. With a NativeSelect I get
final NativeSelect fruitSelect = new NativeSelect( "fruit" );
final TableQuery fruitQuery = new TableQuery( "fruits", pool );
fruitSelect.setNullSelectionAllowed( Boolean.FALSE );
fruitSelect.setItemCaptionPropertyId( "name" );
fruitSelect.setImmediate( Boolean.TRUE );
fruitSelect.setContainerDataSource( new SQLContainer( fruitsQuery ) );
This leads to: javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written.
What am I doing wrong or is this a bug?
Hi again,
I'm intentionally bumping this topic as I consider tying a NativeSelect with an SQLContainer to be core functionality. If they cannot be combined this should be explicitly stated in the documentation and I haven't seen such a statement.
One more thing which puzzles me: if I want to use a FreeformQuery with a delegate, I have to first create a FreeformQuery and then set the delegate, like this:
FreeformQuery freeformQuery = new FreeformQuery( "SELECT * FROM fruits", pool, "id" );
freeformQuery.setDelegate( new FreeformQueryDelegate() {
@Override
public String getQueryString( int offset, int limit ) throws UnsupportedOperationException {
return "SELECT * FROM fruits";
}
[...] rest omitted for clarity
} );
Can you spot the duplication of the query there? Is there any good reasoning behind effectively demanding the query to be repeated? Intuitively I'd expect that there would be a FreeformQuery constructor that supports the creation of a FreeformQuery with a delegate from the very beginning. A constructor, which wouldn't need a query because it's clear that the delegate is going to take care of it...
I'm suffering from this, too. Moreover, it doesn't work either when trying an ComboBox instead, causing a stack overflow. I'm opening a thread for this.