PrimeFaces;无法获得选项列表组件的目标列表

时间:2013-09-19 15:27:49

标签: jsf primefaces jsf-2.2

当我使用命令按钮提交表单时,无法获取目标列表值。

以下是选项列表的源初始化:

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;
}

这是选项列表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>  

这是onTransfer方法启用的ajax:

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);  
}

提交此组件后,源值很好,但即使我在xhtml页面中将数据从源列表传输到目标列表,目标列表也是空的。如何获取目标列表值?

1 个答案:

答案 0 :(得分:0)

// 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));
    }
}