【问题标题】:javax.faces.FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabledjavax.faces.FacesException:启用选择时,DataModel 必须实现 org.primefaces.model.SelectableDataModel
【发布时间】:2012-10-24 01:49:40
【问题描述】:

我有另一个关于这个问题的案例,我有一个扩展基本实体的模型,并且该基本实体具有属性 id。我已将该 id 用作 rowKey,它会引发此错误。当我将 rowKey 的值设置为模型(不是抽象基础)中的任何属性时,数据表可以工作。

请注意,我正在研究 JavaEE6。

模型:

@Entity
@SequenceGenerator(name = "ID_GENERATOR", sequenceName = "USER_ADDRESS_SEQ")
public class UserAddress extends BaseEntity { //.. }

@MappedSuperclass
public abstract class BaseEntity implements Serializable, IEntity {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "ID_GENERATOR")
    @Column(name = "ID")
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    } ..

JavaEE6 bean:

@Stateless
@Named
public class UserAddressBean implements Serializable {
    private static final long serialVersionUID = -6104153017102665096L; 

    private List<UserAddress> addresses;
    private UserAddress address;

    public List<UserAddress> getAddresses() {
        addresses = new ArrayList<UserAddress>();
        UserAddress temp = new UserAddress();
        temp.setDescription("test");
        addresses.add(temp);

        temp = new UserAddress();
        temp.setDescription("test");
        addresses.add(temp);

        return addresses;
    }

    public UserAddress getAddress() {
        return address;
    }

    public void setAddress(UserAddress address) {
        this.address = address;
    }..

还有xhtml页面:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    template="/shared/page/_oneColumn.xhtml">
    <ui:define name="content">
        <h:form id="form">
            <p:panel>
                <f:facet name="header"></f:facet>
                <p:dataTable id="addresses" var="address"
                    value="#{userAddressBean.addresses}" rowKey="#{address.id}"
                    selection="#{userAddressBean.address}" selectionMode="single">
                    <p:column headerText="#{msg['field.description']}">
                        <h:outputText value="#{address.description}" />
                    </p:column>
                </p:dataTable>
                <f:facet name="footer"></f:facet>
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>

对这个问题有什么想法吗?

谢谢,
切苏亚

【问题讨论】:

    标签: jsf primefaces java-ee-6


    【解决方案1】:

    哦,对不起,我太笨了,问题是 id 为空。我忘记了我对这些值进行了硬编码。因此,无论如何,对于将来遇到相同问题的人来说,要使用较少的代码行键,请确保您设置了以下数据表属性: 1.) 行键 2.) 选择 3.) 选择模式

    还要确保 rowKey 属性不为空。

    【讨论】:

      猜你喜欢
      • 2012-05-17
      • 1970-01-01
      • 2016-01-03
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多