Hey,
I have a DropDownChoice for list of users. I want to display user's name
but bind user's ID.
So far I have come to this (ugly) solution that can surely be improved:
// create model with Long userId...
final DropDownChoice<Long> usersDropDown = new DropDownChoice<>(
"userId", Lists.transform(User.getUsers(), new
Function<User, Long>() {
@Nullable
@Override
public Long apply(@Nullable final User user) {
return user.getId();
}
}),
new ChoiceRenderer<Long>() {
@Override
public Object getDisplayValue(final Long id) {
return User.findOne(id);
}
}
);
Thanks for any pointers.
Zbynek