Reputation: 93
I have a problem accesing public enum
class properties inside my JSP page. I am able to access all other's invite class properties except invite.status
attribute. I am doing something wrong, but i just can't figure why it is wrong and how i can access my returned list's enum
values. Thanks for your help solving my issue!
Error what I get The class ...domain.jpa.meeting.Invite
' does not have the property status
.
This is JPA class that I have
@Entity
public class Invite implements PersistentEntity {
@Id @GeneratedValue
private Long id;
@ManyToOne
private User inviter;
@ManyToOne
private User invitee;
@ManyToOne
private Meeting meeting;
/**
* Date when this invite has been created
*/
private Date created;
// @Column(nullable=false, length=1)
// @Enumerated(EnumType.STRING)
private InviteStatus status;
public Long getId() {
return id;
}
public User getInviter() {
return inviter;
}
public void setInviter(User inviter) {
this.inviter = inviter;
}
public User getInvitee() {
return invitee;
}
public void setInvitee(User invitee) {
this.invitee = invitee;
}
public Meeting getMeeting() {
return meeting;
}
public void setMeeting(Meeting meeting) {
this.meeting = meeting;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public InviteStatus getInviteStatus() {
return status;
}
public void setInviteStatus(InviteStatus status) {
this.status = status;
}
}
This is enum type public class that i have
/**
* Values for tracking invite status
*/
public enum InviteStatus {
// invite is created and invitee have not responded yet
CREATED,
// invitee accepted this invite
ACCEPTED,
// invitee declined this invite
DECLINED
}
I am saving in database such way (with success as EnumType.ORDINAL)
// adding invites (table invite)
Invite invite = new Invite();
invite.setInviter(creator);
User invitee = jpaDAO.getById(User.class, Long.parseLong(friends[i]));
invite.setInvitee(invitee);
invite.setInviteStatus(InviteStatus.CREATED); //CREATED = 0, ACCEPTED = 1, ..
Date dateNow = new Date(); //yyyy-MM-dd HH:mm:ss
invite.setCreated(dateNow);
Meeting meeting = jpaDAO.getById(Meeting.class, meetingId);
invite.setMeeting(meeting);
jpaDAO.save(invite);
And i have a method which retrieves invites from database.
@SuppressWarnings({ "unchecked", "null" })
public List<Invite> getUserInvites(Long userId){
// getting invites for current user with status CREATED
Query query = jpaDAO.getEntityManager().createNamedQuery(JPQConst.InviteJpq.QUERY_GET_BY_USER);
query.setParameter("userId", userId);
List<Invite> invites = (List<Invite>) query.getResultList();
return invites;
}
Inside controller it looks like this:
/**
* Display Notifications tab
*/
@RequestMapping(value = "/home/notifications", method = RequestMethod.GET)
public String displayNotifications(ModelMap model, HttpSession session) {
User user = getCurrentUser(session);
List<Invite> invites = notificationService.getUserInvites(user.getId());
model.addAttribute("invites", invites);
return "home";
}
Method itself works, and I am able to access all invite's property fields except status property inside jsp.
<c:forEach var="meeting" items="${inviteeMeetings}">
<c:forEach var="invite" items="${invites}">
<c:choose>
<c:when test="${meeting.id == invite.meeting.id}">
<tr>
<td width="150px" align="center">
<c:out value="${meeting.startTime}" />
</td>
<td width="396px">
<a href="../meeting/${meeting.id}"><c:out value="${meeting.title}" /></a>
</td>
<td width="96px">
<c:out value="${invite.status}" />
<form action="../meeting/attendance" method="post">
<input type="hidden" name="venue" value="${meeting.id}" />
<input type="submit" name="attendance" value="attend" />
<input type="submit" name="attendance" value="reject" />
</form>
</td>
</tr>
</c:when>
</c:choose>
</c:forEach>
</c:forEach>
Upvotes: 1
Views: 1224
Reputation: 24780
Effectively, your class does not have such property. It does have the inviteStatus
property.
public InviteStatus getInviteStatus() {
return status;
}
PROPERTIES ARE BASED IN GETTERS. The name of the internal value that stores the data is not relevant.
Upvotes: 1