JSP页面javax.el.PropertyNotFoundException

时间:2012-09-05 00:25:58

标签: jsp properties javabeans propertynotfoundexception

我的视图模型如下所示:

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如下所示:

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

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

JSP看起来像这样:(viewModel是一个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>

但是我收到了这个错误:

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

我做错了什么?我想我的get / set是对的吗?

1 个答案:

答案 0 :(得分:1)

getter名称为getAlertViewModels(),因此您应该引用alertViewModels(小写A)。