0
我工作的領料單,這裏是我的代碼:PICKLIST:如何檢索所選項目要添加或刪除
XHTML代碼:
<p:pickList id="pickList" value="#{projectAdminisrationMB.selectedUserGroups}"
var="group"
itemLabel="#{group}" itemValue="#{group.name}"
converter="groupConverter"
>
<f:facet name="sourceCaption">Belong To</f:facet>
<f:facet name="targetCaption">Exclude From</f:facet>
<p:column style="width:25%">
<p:graphicImage value="/images/group/#{group.name}.gif" />
</p:column>
<p:column style="width:75%;">
#{group.name}
</p:column>
<p:ajax event="transfer" listener="#
{projectAdminisrationMB.onTransferGroup}" update="growl" />
</p:pickList>
我的轉換器:
package tn.talan.testFramework.converter;
@FacesConverter(value = "groupConverter")
public class GroupConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component,
String value) {
return administrationProjectFinal.getGroupByName(value);
Object ret = null;
if (component instanceof PickList) {
Object dualList = ((PickList) component).getValue();
DualListModel dl = (DualListModel) dualList;
for (Object o : dl.getSource()) {
String id = "" + ((Group) o).getIdBdd();
if (value.equals(id)) {
ret = o;
break;
}
}
if (ret == null)
for (Object o : dl.getTarget()) {
String id = "" + ((Project) o).getIdBdd();
if (value.equals(id)) {
ret = o;
break;
}
}
}
return ret;
}
@Override
public String getAsString(FacesContext context, UIComponent component,
Object value) {
System.out.println("converter group getAsString " + value);
String str = "";
if (value instanceof Group) {
str = "" + ((Project) value).getIdBdd();
}
return str;
}
}
我目標是從選取列表中檢索添加或刪除的項目,所以這裏是 OnTransferGroup方法:
public void onTransferGroup(TransferEvent event) {
if(event.isAdd()){
String resMsg;
System.out.println("dropped group to be excluded");
for(Object item : event.getItems()) {
Group selectedBelongToGroup =(Group) item;
resMsg=administrationProjectFinal.exclureUserGroupFn(selectedBelongToGroup
,selectedUserRow);
if (resMsg.equals("The project should have at least
one administrator"))
{setDeleteGroupFlag(true);
showErrorMsg(resMsg);
}
else droppedBelongToGroups.add(selectedBelongToGroup);
}
}
else if(event.isRemove()){
System.out.println("remove");
System.out.println("dropped group to be included");
for(Object item : event.getItems()) {
Group selectedExcludeFromGroup = ((Group)item);
System.err.println(" n" +selectedExcludeFromGroup.getName());
System.err.println("d "+selectedExcludeFromGroup.getDescription());
droppedExcludeFromToGroups.add(selectedExcludeFromGroup);
administrationProjectFinal.inclureUserGroup(selectedExcludeFromGroup
,selectedUserRow);
}
}
}
問題是event.getItems()列表總是空的。 而當我第一次挑選物品時,onTransferGroup(TransferEvent事件)不會被啓動,但在此之後它會變成一團。
那麼如何檢索添加或刪除