2012-09-05 58 views
1

我的視圖模型是這樣的:JSP頁面javax.el.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看起來是這樣的:(視圖模型是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

吸氣劑名稱是getAlertViewModels(),所以你應該引用alertViewModels(小寫字母A)。

+0

就是這樣,非常感謝! – ConditionRacer