Hi,
as an alternative you can use a custom model instead:
IModel<Long> target = ...;
IModel<User> userModel = new IModel<User>() {
public void setObject(User user) {
target.set(user.getId());
}
public User getObject() {
return User.findOne(target.get());
}
}
Then your choice can just work on a user:
DropDownChoice<User> usersDropDown = new DropDownChoice<>("userId",
userModel, User.getUsers());
Both approaches have advantages and disadvantages.
Have fun
Sven
On 11.01.2017 11:38, Zbynek Vavros wrote:
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
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org