Hi !
I am trying to represent a list of selectable beans in an OptionGroup.
I also need to let the user select nothing when appropriate (so to have an option not bound to a bean)
As far as I understand, this is what the setNullSelectionItemId is designed for.
So this is how I proceeded :
... fill container with items containing a "name" property (BeanItemContainer) ...
OptionGroup group = new OptionGroup();
group.setNullSelectionAllowed(true);
String nullSelectionString = new String("Null selection");
group.addItem(nullSelectionString);
group.setNullSelectionItemId(nullSelectionString);
group.setItemCaptionPropertyId("name");
group.setContainerDataSource(container);
This code makes the application crash during the rendering with the following error :
java.lang.NullPointerException
at com.vaadin.data.util.BeanItemContainer.getContainerProperty(BeanItemContainer.java:482)
at com.vaadin.ui.AbstractSelect.getContainerProperty(AbstractSelect.java:745)
at com.vaadin.ui.AbstractSelect.getItemCaption(AbstractSelect.java:1092)
at com.vaadin.ui.AbstractSelect.paintItem(AbstractSelect.java:376)
at com.vaadin.ui.OptionGroup.paintItem(OptionGroup.java:69)
at com.vaadin.ui.AbstractSelect.paintContent(AbstractSelect.java:334)
at com.vaadin.ui.OptionGroup.paintContent(OptionGroup.java:63)
at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
at com.vaadin.ui.AbstractOrderedLayout.paintContent(AbstractOrderedLayout.java:171)
at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
at com.vaadin.ui.Panel.paintContent(Panel.java:247)
at com.vaadin.ui.Window.paintContent(Window.java:621)
at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.writeUidlResponce(AbstractCommunicationManager.java:1019)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(AbstractCommunicationManager.java:906)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:829)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:291)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:481)
....
The same code works when adding the items using “group.addItem” instead of using setContainerDataSource.
Using setContainerDataSource also works well I remove the null selection related code.
Am I doing something wrong ?