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:
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.
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.