简体   繁体   中英

PrimeFaces; can't get target list of picklist component

I can't get target list values when I submit the form with command button.

Here is the source initialization of picklist:

public DualListModel<VehicleType> getVehicleTypeList() {

    List<VehicleType> source = new ArrayList<VehicleType>();  
    List<VehicleType> target = new ArrayList<VehicleType>();  

    source = dao.getVehicleTypes(getLocale());     

    vehicleTypeList = new DualListModel<VehicleType>(source, target);
    return vehicleTypeList;
}

Here is the picklist xhtml:

<p:pickList id="pojoPickList" value="#{home.vehicleTypeList}" var="vehicleType" effect="slide"  
itemValue="#{vehicleType}" itemLabel="#{vehicleType.vehicleTypeName}" 
showSourceControls="true" showTargetControls="true" showCheckbox="true"  
showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains" 
style="padding-left:50px;" binding="#{home.selectedVehicleTypes}">  

<p:ajax event="transfer" listener="#{home.onTransfer}"/>

<f:facet name="sourceCaption">Mevcut Araçlar</f:facet>  
<f:facet name="targetCaption">Seçilen Araçlar</f:facet>  

<p:column style="width:25%">  
    <p:graphicImage id="typeImg" value="/images/icons/#{vehicleType.iconFileName}" width="40" height="40" />  
</p:column>  

<p:column style="width:75%;">  
    <h:outputText id="vhclTypeName" value="#{vehicleType.vehicleTypeName}"/> 
</p:column>  

Here is the ajax enabled onTransfer method:

public void onTransfer(TransferEvent event) {  
    StringBuilder builder = new StringBuilder();  
    for(VehicleType type : vehicleTypeList.getTarget()) {  
        builder.append(type.getVehicleTypeName() + " ");  
    }  

    FacesMessage msg = new FacesMessage();  
    msg.setSeverity(FacesMessage.SEVERITY_INFO);  
    msg.setSummary("Items Transferred");  
    msg.setDetail(builder.toString());  

    FacesContext.getCurrentInstance().addMessage(null, msg);  
}

After submitting this component, source values are fine but the target list is empty even if I transfer data from source to target list in the xhtml page. How can I get the target list values?

// should be something like this (did not test it though)
public void onTransfer(final TransferEvent event) {
    for (final Object each : event.getItems()) {
        vehicleTypeList.getTarget().add(((VehicleType) each));
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM