Q:

PickList : How to retrieve selected item to be added or removed

i'm working on picklist here's my code :
xhtml code :
    <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> 

My converter :
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;

}
  }

My aim is to retrieve the added or removed item from the picklist so here's the 
OnTransferGroup method :
 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);

         }

     }                   

         }  

The problem is that the  event.getItems() list is always empty .
And the  onTransferGroup(TransferEvent event) is not lunched when i pick item for the first time but it is luched after that.
So how to retrieve selected item to be added or removed

A:

You put a "return" on the first statement of the "getAsObject" method so it won't reach the rest of the logic.
Also, if you're getting a null return value out of the getItems method, it surely means a Converter issue, so check the above.

