0

当用户将项目从一个列表转移到另一个列表时,我想更新 bean 中的列表。有没有办法做到这一点?

谢谢。

4

2 回答 2

2

在 xhtml 中:

<p:pickList value="#{myBean.myDepartment}" onTransfer="handleTransfer(e)"....>

在豆子里:

List<Department> selectedDepartments = new ArrayList<Department>();
List<Department> availableDepartments = getAvailableDepartments();

private DualListModel<Department> myDepartment;
myDepartment = new DualListModel<Department>(availableDepartments, selectedDepartments);

提交时,可以使用 selectedDepartments 访问用户选择的部门

还有剧本...

<script type="text/javascript">
function handleTransfer(e) {
    item = e.item;
    alert(item.text());

    fromList = e.from;
    toList = e.to;
    type = e.type; //type of transfer; command, dblclick or dragdrop)
}
</script>
于 2012-05-17T05:17:44.460 回答
0

I don't exactly know what do you want. This is done automatically same as if you type something into p:inputText it is available in beans property representing the value of p:inputText without need of manual update.

Just access the updated values in your pickList with getTarget() or getSource() methods. You are probably trying to access lists which you provided to DualListModel directly like:

DualListModel<fooType> fooModel = new DualListModel<fooType>(fooList1,fooList2);
// transfer item
// check if fooList2 is updated - this is wrong, it is **not** updated
fooModel.getTarget(); // this way you can get the actual values of target list 

target - right side, source - left side of a pickList.

于 2012-05-16T19:24:53.057 回答