gpt4 book ai didi

java - Wicket CheckBoxMultipleChoice 不更新

转载 作者:行者123 更新时间:2023-12-01 15:49:33 24 4
gpt4 key购买 nike

我的 Wicket 面板需要至少单击两次才能使用按钮的 onSubmit 方法更新任一 CheckBoxMulitpleChoice 组件。如何让这些组件在第一次点击时更新?

我正在使用两个 CheckBoxMultipleChoice 组件来编译要通知的用户列表。第一个是根据 DropDownChoice 团队选择中可用的用户填充的。然后,用户可以从该团队中选择用户以添加到第二个 CheckBoxMultipleChoice,该复选框显示要通知的所有用户并允许用户删除用户。

我尝试过使用 Palette 组件,但使用的是 wicket 1.3.1(我在迁移到 1.4 时遇到了麻烦,但这是另一篇文章的内容),并且未能成功控制 UI。我也尝试过将组件放置在表单中,但这并没有改变功能。至少需要单击 2 次才能在复选框中添加或删除条目。看来 getValue() 直到执行按钮行为后才会更新。

        // Team selection for notification =================================
final DropDownChoice teamNotificationChoice = new DropDownChoice("teamNotification", teamList, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((Team) o).getName();
}
public String getIdValue(Object o, int i) {
return Long.toString(((Team) o).getId());
}
});
notifySelectionList.add(teamNotificationChoice);

// teamUser selection list for notification ========================
List<ItemUser> choices = UserUtils.convertToItemUserListFromUsers(getJtrac().findUsersForSpace(space.getId()));
teamUsers = new CheckBoxMultipleChoice("teamUsers", choices, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((ItemUser) o).getUser().getName();
}
public String getIdValue(Object o, int i) {
return ((ItemUser) o).getUser().getLoginName();
}
});
notifySelectionList.add(teamUsers);

// Add selected teamUsers button ===================================
Button button = new Button("addUsersToList") {
@Override
public void onSubmit(){
}
};
button.add(new AjaxFormComponentUpdatingBehavior("onClick") {
protected void onUpdate(AjaxRequestTarget target) {
List choices = teamUsers.getChoices();
String value = teamUsers.getValue();
for (int index = 0; index < choices.size(); index++) {
final ItemUser choice = (ItemUser) choices.get(index);
if(isSelected(choice, index, value)&!userSelection.contains(choice)) {
userSelection.add(choice);
}
}
SortUtils.sortItemUsers(userSelection);
itemUsers.setChoices(userSelection);
target.addComponent(itemUsers);
}
});
notifySelectionList.add(button);
notifySelectionList.setOutputMarkupId(true);

// notify list ===================================================
itemUsers = new CheckBoxMultipleChoice("itemUsers", userSelection, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((ItemUser) o).getUser().getName();
}
public String getIdValue(Object o, int i) {
return ((ItemUser) o).getUser().getLoginName();
}
});
itemUsers.setMaxRows(10);
itemUsers.setOutputMarkupId(true);
notifyList.setOutputMarkupId(true);
notifyList.add(itemUsers);

// Remove selected teamUsers button ===================================
Button removeButton = new Button("removeUsersFromList") {
@Override
public void onSubmit(){
}
};
removeButton.add(new AjaxFormComponentUpdatingBehavior("onClick") {
protected void onUpdate(AjaxRequestTarget target) {
List choices = itemUsers.getChoices();
String value = itemUsers.getValue();
for (int index = 0; index < choices.size(); index++) {
final ItemUser choice = (ItemUser) choices.get(index);
if(isSelected(choice, index, value)) {
userSelection.remove(choice);
}
}
itemUsers.setChoices(userSelection);
target.addComponent(itemUsers);
}
});
notifyList.add(removeButton);

预先感谢您提供的任何建议...

最佳答案

好吧,我不知道是否有人关心,因为我没有得到任何反馈,我认为这不是一个常见问题,但我会将我的解决方案放在这里,以防万一它可以帮助别人。

我可以通过删除 AjaxFormComponentUpdatingBehavior() 并仅使用按钮的 onSubmit() 方法来解决这个问题。我还在按钮上设置了 setDefaultFormProcessing(false) ,以便仅更新 CheckboxMultipleChoice 面板。现在看起来如下:

        // Team selection for notification =================================
final DropDownChoice teamNotificationChoice = new DropDownChoice("teamNotification", teamList, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((Team) o).getName();
}
public String getIdValue(Object o, int i) {
return Long.toString(((Team) o).getId());
}
});
notifySelectionList.add(teamNotificationChoice);

// teamUser selection list for notification ========================
List<ItemUser> choices = UserUtils.convertToItemUserListFromUsers(getJtrac().findUsersForSpace(space.getId()));
teamUsers = new JtracCheckBoxMultipleChoice("teamUsers", choices, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((ItemUser) o).getUser().getName();
}
public String getIdValue(Object o, int i) {
return ((ItemUser) o).getUser().getLoginName();
}
});
notifySelectionList.add(teamUsers);

// Add selected teamUsers button ===================================
Button button = new Button("addUsersToList") {
@Override
public void onSubmit(){
List choices = teamUsers.getChoices();
String value = teamUsers.getValue();
for (int index = 0; index < choices.size(); index++) {
final ItemUser choice = (ItemUser) choices.get(index);
if(isSelected(choice, index, value)&!userSelection.contains(choice)) {
userSelection.add(choice);
}
}
SortUtils.sortItemUsers(userSelection);
itemUsers.setChoices(userSelection);
notifyList.add(itemUsers);
teamUsers.updateModel();
}
};
button.setDefaultFormProcessing(false);
notifySelectionList.add(button);
notifySelectionList.setOutputMarkupId(true);

// notify list ===================================================
itemUsers = new JtracCheckBoxMultipleChoice("itemUsers", userSelection, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((ItemUser) o).getUser().getName();
}
public String getIdValue(Object o, int i) {
return ((ItemUser) o).getUser().getLoginName();
}
});
itemUsers.setMaxRows(10);
itemUsers.setOutputMarkupId(true);
notifyList.setOutputMarkupId(true);
notifyList.add(itemUsers);

// Remove selected teamUsers button ===================================
Button removeButton = new Button("removeUsersFromList") {
@Override
public void onSubmit(){
List choices = itemUsers.getChoices();
String value = itemUsers.getValue();
if(value!=""){
String[] valueList = itemUsers.getValue().split(";");
List<User> userList = new ArrayList<User>();
for (String s:valueList){
userList.add(getJtrac().loadUser(s));
}
List<ItemUser> itemUserList = UserUtils.convertToItemUserListFromUsers(userList);
for (ItemUser iu:itemUserList) {
userSelection.remove(iu);
}
itemUsers.setChoices(userSelection);
notifyList.add(itemUsers);
}
}
};
removeButton.setDefaultFormProcessing(false);
notifyList.add(removeButton);

关于java - Wicket CheckBoxMultipleChoice 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6392267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com