如何在Apache Wicket中选择下拉菜单中的多个选项?

3
有没有使用PropertyModel在Apcahe Wicket中选择多个下拉列表值的方法?
2个回答

1
你可以使用ListMultipleChoice。
比如说,你有一个用户列表,你想要在多选下拉框中填充这个列表。 你可以像这样做:
ListMultipleChoice<?> multiChoice = new ListMultipleChoice<Object> 
    ("usermultiSelect", 
     (IModel<? extends Collection<Object>>) new PropertyModel<Object>(properties,"selectedUsers"),
     users);

此外,您可以注册更改侦听器以对所选数据进行一些处理。
    multichoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            List<User> users = (List<User>) properties.get("selectedUsers");   
            // do whatever you want to do with the users list
        }
    };

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接