0

Here's my model:

public class Class {
    @ManyToMany(etc etc)
    @JoinTable(etc etc)
    public List<Course> Courses;

Here's my view:

<c:forEach items="${classes}" var="class">
<tr>
    <td>${class.className}</td>
    <td>
    <c:forEach items="${courses}" var="course">
        <input type="checkbox"
            <c:if test="${class.Courses.contains(course)}"> checked</c:if>>
        ${course.courseName}
    </c:forEach>
    </td>
</tr>
</c:forEach>

The view only produces this 500 error:

javax.el.PropertyNotFoundException: The class 'com.springapp.mvc.Class' does not have the property 'Courses'.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
joakim
  • 1,612
  • 1
  • 14
  • 23

1 Answers1

0

EL do not look for properties but for getters:

public class AnyClass {

  private String aProperty;

  private String getAGetter() {
    // ...
  }

}

${anyClass.aProperty} will fail, ${anyClass.aGetter} will succeed.

To transform a getter name into an EL expression, the "get" (or "is") prefix is removed, and the first char is lowercased.

In your case, I guess your getter name is getCourses, which gives courses. So you have to use ${class.courses}.


Be aware that you do not follow the Java naming conventions.

sp00m
  • 47,968
  • 31
  • 142
  • 252