domdomcodecode
domdomcodecode

Reputation: 2453

Why <s:property> tag can't access abstract parent class member in Struts 2?

I'm having problems accessing a property via Struts. I was wondering, if anyone, who's more experienced with Struts, would be able to give me a few pointers?

The Java classes are roughly set up like this:

public abstract class parent{
    protected Integer id;

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

public class child extends parent{
    // stuff
}

The child is a list in an action class with getter set up:

private List<child> childList;

This is my code in the front end, attempting to grab the id property:

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

However, nothing shows up. I've grabbed other members from the child class, so I'm assuming there's an issue with the parent member, I'm grabbing being in an abstract class?

UPDATE:

I've attempted to grab another property in the abstract class in the JSP and it works fine. The other property I grabbed is creationDate. I've also added breakpoints to the id getter and it's being accessed fine and returning non-null values. Here is a more detailed implementation of the parent with Hibernate annotations included:

@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;
    }
}

Upvotes: 2

Views: 1181

Answers (1)

Roman C
Roman C

Reputation: 1

The problem is in

private List<child> childList;

it requires

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

in JSP

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

Upvotes: 2

Related Questions