Primefaces PickList update target list on transfer

我怕爱的太早我们不能终老 提交于 2019-12-24 20:39:49

问题


I want to update the lists in the bean when the user transfers an item from one list to another. Is there a way to do that?

Thx.


回答1:


In the xhtml:

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

In the bean:

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

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

On Commit, Departments selected by the user can be accessed using selectedDepartments

And the script ...

<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>



回答2:


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.



来源:https://stackoverflow.com/questions/10622582/primefaces-picklist-update-target-list-on-transfer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!