我正在尝试开发 2 个listmultiplechoice框来将值从一个 list{source} 加载到另一个 list{destination} 并使用Ajaxbuttons将值相互加载。当我单击 ajax 按钮时,我能够看到 java 类中的值,但是这些值没有正确加载到 UI 上的目标 listmultiplechoice 框中。我已经在下面发布了我的代码,请。检查并让我知道这里出了什么问题?
private AjaxButton add;
private AjaxButton remove;
private List selectedOriginals;
private List selectedDestinations;
private ListMultipleChoice originals;
private ListMultipleChoice destinations;
private List<String> currentDestinations = new ArrayList<String>();
originals = new ListMultipleChoice("originals", new PropertyModel(this, "selectedOriginals"),APPLICATIONS);
originals.setOutputMarkupId(true);
add(originals);
destinations = new ListMultipleChoice("destinations", new PropertyModel(this, "selectedDestinations"), new LoadableDetachableModel()
{
@Override
protected Object load()
{
return currentDestinations;
}
});
destinations.setOutputMarkupId(true);
add(destinations);
add = new AjaxButton("add")
{
@Override
protected void onError(AjaxRequestTarget target, Form form)
{
System.out.println("Some error in AJX submission....");
target.addComponent(feedbackPanel);
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form form)
{
update(target,selectedOriginals, originals, destinations);
}
};
add.setOutputMarkupId(true);
add(add);
remove = new AjaxButton("remove")
{
@Override
protected void onError(AjaxRequestTarget target, Form form)
{
System.out.println("Some error in AJX submission....**********************");
target.addComponent(feedbackPanel);
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form form)
{
update(target, selectedDestinations, destinations, originals);
}
};
remove.setOutputMarkupId(true);
add(remove);
更新方法::
private void update(AjaxRequestTarget target, List<String> selections, ListMultipleChoice from, ListMultipleChoice to)
{
if(selections != null)
{
for (String destination : selections)
{
List<String> choices = getChoices(from);
if (!to.getChoices().contains(destination))
{
to.getChoices().add(destination);
choices.remove(destination);
from.setChoices(choices);
}
}
target.addComponent(to);
target.addComponent(from);
}
}