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