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.
ListSelect in Form help
Hello all,
I am using a Form; here is the field factory:
private class MyFieldFactory extends DefaultFieldFactory
{
private ListSelect ls;
public MyFieldFactory()
{
super();
ls = new ListSelect("Included Stuff : ");
ArrayList<Stuff> possible = new ArrayList<Stuff>(getStuffList());
possible.remove(item);
if (possible.size() > 0)
{
ls.setContainerDataSource(new BeanItemContainer(possible));
}
}
@Override
public Field createField(Item myItem, Object propertyId, Component uiContext)
{
if("includedStuff".equals(propertyId))
{
return ls;
}
Field f = super.createField(myItem, propertyId, uiContext);
if ("name".equals(propertyId))
{
TextField tf = (TextField) f;
tf.setRequired(true);
tf.setCaption("Name : ");
tf.setRequiredError("Enter a stuff name.");
tf.addValidator(new StringLengthValidator("Name must be at least 3 characters, no more than 255.", 3, 255, false));
}
return f;
}
}
I have an "Add / Edit" button to go with this. If I remove the ListSelect, the Form works as expected. With the ListSelect, when I click the "Add / Edit" button, I get this StackTrace:
com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: support.OrderedArrayList.(java.lang.String)
at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:709)
at com.vaadin.ui.AbstractField.commit(AbstractField.java:226)
at com.vaadin.ui.Form.commit(Form.java:312)
at com.flphsys.vaadin.CallRoutesLayout$2.buttonClick(CallRoutesLayout.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1107)
at com.vaadin.ui.Button.fireClick(Button.java:341)
at com.vaadin.ui.Button.changeVariables(Button.java:177)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1060)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:561)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:260)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:438)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
OrderedArrayList is simply a wrapper around ArrayList that inserts items in Alphabetical order.
What am I doing wrong?
I'm a vaadin newbie, so take my answer with that in mind... I've not used ListSelect before, but I have used TwinColSelect and found that my bean needed to get/set a Set, not an array (not sure about a List). If that's the case, then your bean should have methods like:
public Set<Stuff> getStuff() {...}
public void setStuff(Set<Stuff> s) {...}
Or if it does support lists, they may need to be the more generic List<Set> used in the get/set rather than ArrayList. Good luck!
David,
You were right! And in my experimentation, for the TwinColSelect (I love it) and the ListSelect to work, your getters need to return a Set<> and your setters need to take a Set<>. No extensions on Set - i.e. HashSet won't work in getter or setter.
I wonder why it is coupled so tightly with a Set instead more loosley with a Collection....
Probably because a Set has no repetitions and makes no promises on ordering. So it feels like the right contract.