Issue with ValueListBox

721 views
Skip to first unread message

Steve

unread,
Mar 9, 2011, 11:20:16 AM3/9/11
to Google Web Toolkit
Having an issue with ValueListBox in GWT 2.1. I'm probably just doing
something wrong! I build a ValueListBox:

storeListBox = new ValueListBox<Stores>(new Renderer<Stores>() {
@Override
public String render(Stores object) {
return object.getStoreName();
}

@Override
public void render(Stores object, Appendable appendable)
throws IOException {

}
});

Then, later on to populate, I apply a list of Stores objects --


storeListBox.setAcceptableValues(app.getStoresList());

Everything if fine, except this -- I can see when I look at the Stores
list, it has 3 elements in the list. However, the render method is
getting invoked FOUR times, and the fourth time is getting null passed
in as the object. I can clearly see that there are only three
elements in the list and that the null invokation is after it has done
all the objects in the list.

I can condition the return on object not being null, but I need to
return something from the render method and that is getting added
erroneously to the ValueList.

What am I doing wrong?

Thanks in advance

Thomas Broyer

unread,
Mar 9, 2011, 11:27:37 AM3/9/11
to google-we...@googlegroups.com
ValueListBox automatically adds any value passed to setValue() to the list of "acceptable values", so you probably have some setValue(null) somewhere, or it might rather be that you don't have a setValue() anywhere, so the ValueListBox tries to select the default value (null) in the list, and adds it to the list of "acceptable values" as a consequence.

Steve

unread,
Mar 9, 2011, 1:16:12 PM3/9/11
to Google Web Toolkit
Thanks, that was it!

For anyone who gets to this post by a search, Thomas was correct --
the problem was that I had not set a value, but added acceptible
values. So since it had no value, it added "null" to the list. I
resolved it by setting the value PRIOR to setting the acceptible
values, like this --

storeListBox.setValue(currentStore);
storeListBox.setAcceptableValues(app.getStoresList());

And that resolved the issue.

Eugen Paraschiv

unread,
Jun 9, 2011, 4:15:45 AM6/9/11
to google-we...@googlegroups.com
I just ran into the exact same thing, where I was setting the acceptable values without explicitly setting a value first - null is added to the list. I understand the fix, but this seems to be an issue - if no value is set, then it would make sense to have a way to skip the adding of the null - just select the first element. If not, at least document the behavior of setAcceptableValues in it's javadoc, because the behavior is unexpected and needs to be documented.
Any thoughts on this?
Eugen.

l3dx

unread,
Jun 19, 2011, 6:09:43 PM6/19/11
to Google Web Toolkit
This also caused me some trouble. Could not understand where that
'null' came from.
Reply all
Reply to author
Forward
0 new messages