Struts 2属性标记无法访问抽象父类成员

时间:2014-04-24 08:31:09

标签: java hibernate jsp struts2

我在通过struts访问属性时遇到问题。我想知道是否有任何对struts更有经验的人能够给我一些指示。

java类大致设置如下:

public abstract class parent{
    protected Integer id;

    public Integer getId(){
        return this.id;
    }
}

public class child extends parent{
    // stuff
}

子项是设置了getter的动作类中的列表:

private List<child> childList;

这是我在前端的代码,试图抓住id属性:

<s:iterator value="childList" status="cStatus">
    <s:property value='id' />
</s:iterator>

然而,没有任何表现。我从子类中抓住了其他成员,所以我假设父成员有一个问题我正在抓住一个抽象类?

更新

我试图在jsp的抽象类中抓取另一个属性,但它运行正常。我抓住的另一个属性是creationDate。我还在id getter中添加了断点,并且可以正常访问它并返回非空值。以下是包含hibernate注释的父级的更详细实现:

@MappedSuperclass
public abstract class parent{
    protected Integer id;
    protected Date creationDate;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @DocumentId
    public Integer getId() {
        return this.id;
    }

    protected void setId(Integer id) {
        this.id = id;
    }

    @Column(updatable=false, nullable=false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreationDate() {
        return this.creationDate;
    }

    @SuppressWarnings("unused")
    private void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }
}

1 个答案:

答案 0 :(得分:2)

问题在于

private List<child> childList;

需要

private List<child> childList = new ArrayList<>();
public List<child> getChildList(){
  return childList;
}
JSP中的

<s:iterator value="childList" status="cStatus">
    <s:property value="id" />
</s:iterator>