p:dataTable单选单选按钮错误:无法强制转换为java.util.Collection

时间:2015-02-18 12:54:44

标签: jsf primefaces datatable

Primefaces 4.0

您好,我正尝试使用单选按钮实现<p:dataTable>。该表是正确的,但是当U提交页面时,我收到以下错误:

java.lang.ClassCastException: [Lpt.ef.besa.pe.common.api.TermDepositProduct; cannot be cast to java.util.Collection
    at org.primefaces.component.datatable.DataTable.getRowData(DataTable.java:977)
    at org.primefaces.component.datatable.feature.SelectionFeature.decodeSingleSelection(SelectionFeature.java:47)
    at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:38)
    at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:60)
    at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
    at org.primefaces.component.api.UIData.processDecodes(UIData.java:232)
    at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)

我的数据表代码:

<p:dataTable var="product" value="#{availableTermDepositProducts.rows}" selection="#{form.product}"
            emptyMessage="#{i18n['messages.global.dataTable.emptyMessage']}" rowKey="#{product.id}">

            <p:column selectionMode="single" />
            ...columns
</p:dataTable>'

我的支持bean:

public class TermDepositProductSubscriptionFormBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private TermDepositProduct product;
    private String productId;
    private boolean automaticRenewal;
    private boolean interestCapitalization;
    private BigDecimal amount;

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public boolean isAutomaticRenewal() {
        return automaticRenewal;
    }

    public void setAutomaticRenewal(boolean automaticRenewal) {
        this.automaticRenewal = automaticRenewal;
    }

    public boolean isInterestCapitalization() {
        return interestCapitalization;
    }

    public void setInterestCapitalization(boolean interestCapitalization) {
        this.interestCapitalization = interestCapitalization;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public TermDepositProduct getProduct() {
        return product;
    }

    public void setProduct(TermDepositProduct product) {
        this.product = product;
    }
}

如果使用单一选择,为什么它会继续尝试转换为集合?

-Thanks

1 个答案:

答案 0 :(得分:0)

目前不支持带数组的数据表选择,因此我将使用集合填充数据表。

我虽然Primefaces试图将Selected Item转换为集合,但是它试图转换我用来填充数据表的Array,因此错误。我没有注意阅读错误日志。