cze*_*uya 2 jsf primefaces java-ee-6
我有另一个案例就是这个问题,我有一个模型,它扩展了一个基本实体,并且该基本实体具有属性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;
} ..
Run Code Online (Sandbox Code Playgroud)
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;
}..
Run Code Online (Sandbox Code Playgroud)
和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>
Run Code Online (Sandbox Code Playgroud)
对这个问题有什么想法吗?
谢谢,
czetsuya
cze*_*uya 12
哦对不起,我是如此愚蠢,问题是id为null.我忘记了我对这些值进行了硬编码.所以无论如何,对于将要遇到相同问题的未来人来说,要使用较少的代码行密钥,请确保设置了以下数据表属性:1.)rowKey 2.)选择3.)selectionMode
还要确保rowKey属性不为null.
归档时间: |
|
查看次数: |
10049 次 |
最近记录: |