Reputation: 5063
I have another case for this issue which is, I have a model that extends a base entity and that base entity has property id. I've use that id as the rowKey and it throws this error. When I set rowKey's value to any property from the model (not the abstract base) the datatable works.
Note that I'm working on JavaEE6.
The models:
@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;
} ..
The 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;
}..
And the xhtml page:
<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>
Any idea for the problem?
Thanks,
czetsuya
Upvotes: 2
Views: 10336
Reputation: 5063
Oh sorry, I was so stupid, the problem was id is null. I forgot that I hard coded the values. So anyway for the future people who would encounter the same issue, to make use of the less code row key make sure that you have the following datatable properties set: 1.) rowKey 2.) selection 3.) selectionMode
Also make sure that the rowKey property is not null.
Upvotes: 12