0

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

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

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

这是启用 ajax 的 onTransfer 方法:

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 页面中将数据从源列表传输到目标列表,源值也可以,但目标列表为空。如何获取目标列表值?

4

1 回答 1

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));
    }
}
于 2013-12-02T17:18:59.347 回答