Pergunta

I can't find how to persist the list of elements (target) choosen in a primefaces picklist.

  <p:pickList id="pojoPickList" value="#{associationMBean.allVisas}" itemValue="#{visa}" itemLabel="#{visa.visaNum}" var="visa" style="width: 400px !important" converter="com.gis.visasmarketing.objectConverters.VisaConverter"  required="true"  showSourceControls="false" showTargetControls="false" showCheckbox="true"  
                                    showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains" >  
     <f:facet name="sourceCaption">All Visas</f:facet>  
     <f:facet name="targetCaption" >Selected Visas</f:facet>  
     <p:ajax event="transfer" listener="#{associationMBean.onTransfer}"  />   
     <p:column style="width:75%;">  
       #{visa.visaNum} #{visa.traveller.firstName} #{visa.traveller.lastName}
     </p:column>  
 </p:pickList> 

This picklist is working fine: it move values from one list to another list. But i don't know how to get the elements selected in the target list to persist them with a command button.

Any help please??

Foi útil?

Solução

The p:ajax is OK, if it's not calling the bean, try to update your PF to 4.0

If you want to get the picklist target on your commandbutton, just use : picklist.getTarget();

If you want to do that in your onTransfer event, do the following:

private DualListModel<yourEntity> allVisas = new DualListModel<yourEntity>();   

public void onTransfer(){
List<yourEntity> target = allVisas.getTarget();
}

Outras dicas

The TransferEvent has getItems() method. It containts transferred items. You can use these methods to check which events triggered listener:

isAdd() : Is transfer from source to target

isRemove() : Is transfer from target to source

The code:

public void onTransfer(TransferEvent event){
     if(event.isAdd())
       //persist event.getItems()
     (...)
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top