Bug in the Five Minutes Tutorial

Hello

I am a new user of Vaadin, starting by making a project in Eclipse, pasting the code of the
Five Minute Tutorial
and hacking it a bit.
I had to hunt down the information that I had to add
?restartApplication
at the end of the Tomcat URL to see my changes (eg. label renaming).
I also had a deprecation warning on the SplitPanel component, I suggest to update the tutorials using it to switch to HorizontalSplitPanel or the vertical one.

While testing the application, I could test the nice exception reporting when I clicked on the + button… It was the opportunity to debug the application, which is a pleasure to do (easy and efficient).
I found out that in the handler of initContactAddRemoveButtons, we call addItemAt(0), then we do getItem(id). But I found out that the latter operation can return null! Hence the exception.
Why do we get null? Because I clicked the button while filtering the list! So the empty item was automatically removed from the view, and cannot be found back…

I just avoided to use the item if null, but it isn’t a satisfying solution as it remains empty and out of view. We should at least be able to change it to John Doe, but as a newbie, I don’t know yet if it can be done, and how.

So I suggest to update this code to handle this case (or just disable the + button when filtering the list…).

So far, I find Vaadin very intuitive to use, I really like it! I must do a quick prototype with it, and I believe I will get it done much faster than if I had to use SmartGWT or similar… :slight_smile:

I found out addItemAt(int index, Object newItemId) that returns the item, but then I have to manage myself all the ids, since IndexedContainer.generateId() is private…
I see no simple way to access this newly created item if it is filtered out.
And since the behavior would be confusing anyway (creating an entry with an arbitrary name and not being able to see it), my version just hides the + button when there is at least one filter.

I found the protected
getUnfiltedItem()
, but as said, it is better to disable adding items while filtering out (or to change the way to create new items, eg. with a new dialog, but that’s another story).
I created a
class AddressBookData extends IndexedContainer
to be able to access the
getFilters()
method. The constructor uses the body of
createDummyData()
. I added a method
public boolean IsFiltered() { return getFilters().size() > 0; }

I made a
contactAddingButton
and in the filtering listener, I do
contactAddingButton.setVisible( !( (AddressBookData) addressBookData ).IsFiltered() );

Works well.

It was a good opportunity to dive into Vaadin hacking and doc. navigating. The ride is nice so far.