对于这个问题,我还有另一种情况,即我有一个扩展基本实体的模型,并且该基本实体具有属性 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>
对这个问题有任何想法吗?
谢谢,
czetsuya