Question

My view model looks like this:

public class HomePageViewModel {
    private List<AlertViewModel> alertViewModels;
    public List<AlertViewModel> getAlertViewModels() { 
        return alertViewModels;
    }
    public void setAlertViewModels(List<AlertViewModel> alertViewModels) {
        this.alertViewModels = alertViewModels;
    }

    public HomePageViewModel(){
        alertViewModels = new ArrayList<AlertViewModel>();
    }
}

AlertViewModel looks like this:

public class AlertViewModel {
    private String id;
    public String getId(){
        return id;
    }
    public void setId(String id){
        this.id = id;
    }

    public AlertViewModel(){
        id = "";
    }
}

JSP looks like this: (viewModel is a HomePageViewModel)

<table border="1">
    <tr>
    <th>Id</th>
    </tr>

    <c:forEach items="${viewModel.AlertViewModels}" var="alert">
      <tr>
      <td>${alert.Id}</td>
      </tr>
    </c:forEach>    
</table>

But I get this error:

HTTP ERROR 500

Problem accessing /. Reason:

Could not find property AlertViewModels in class viewmodels.HomePageViewModel
Caused by:

javax.el.PropertyNotFoundException: Could not find property AlertViewModels in class viewmodels.HomePageViewModel

What am I doing wrong? I think I have the get/set correct right?

Was it helpful?

Solution

The getter name is getAlertViewModels(), so you should be referencing alertViewModels (lowercase A).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top