ComboBox select.setValue problems with BeanItemContainer

I’ve looked at the examples, etc. regarding setValue for a ComboBox. I have this code in a Factory instance.

         ComboBox select = new ComboBox("Assigned To", ContainerUtils.getObjectContainer(User.class, "department_id", dept.getDeptID()));
         select.setNewItemsAllowed(false) ;
         select.setMultiSelect(false) ;
         select.setImmediate (true) ;

         if (null != srv && null != srv.getAssignedTo())
            select.setValue(srv.getAssignedTo()) ;

The “srv” instance is declared at the top of the factory and is a valid instance of
the object “Services” which has a member called “assignedTo” which is of type “User”.

The “ContainerUtils” call creates a BeanItemInstance for the class passed in and it is filtered according to the parameters. This works fine and the correct values are present.

I’ve tried all sorts of variations in other forum posts and nothing works to select the value
in the combo. The value is definitely there- already debugged the instance to confirm that.

“User” implements equals and hashCode.

The problem is that the internal call to setValue(Object, boolean) always returns false. No matter what I pass in as the property id- the actual string instance of the name, or the whole User object.

Any help would be much appreciated.


I’m not quite sure what your problem could be. What type does the getAssignedTo() return? I think it should work with the User object, assuming that the container is a BeanItemContainer. What is the BeanItemInstance you mention?

this example
does much the same thing and works. The getIdByIndex() returns the bean object, as it is used as the item ID in the BIC.

I suspect that your equals() or hashCode() do not behave quite like the framework expects.

However, if your User beans have some natural identifier, I’d recommend using a BeanContainer instead of a BeanItemContainer. That way, you can explicitly give IDs or generate them from the beans.

Thanks Marko for the suggestion.

getAssignedTo() returns a User instance. I think the problem is related to nesting.

The field factory is for the parent class “Services” and the custom UserField is for the child instance “assignedTo”.

I’ll check out the example. Thanks.

Thanks Henri.

I’ll try that. the equals & hasCode do have explicit unqiue ids to work from, so I don’t think that’s the problem, which I’ve had in the past, so I catch that one early one.

I’ll try the BeanContainer instead of the BeanItemContainer.