I m doing a small spring project and I have an issue when I try toi show data iterating resultList, resultList is set and foreach loop over 4 times as items there are but giveme an exceptions, after going through I realize that items are retrive but if they were just Object instead of porper cast class Result for this reason It crash when I try to invoke getUrl() method (if I call toString works fine).
that's the controller
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ModelAndView home(ModelMap model,@RequestParam(required=false,value="") String name) {
List<Result> result = googleSearchService.doSearch(name);
modelAndView.addObject("resultList",result);//<- after debub list is full of Result items
return modelAndView;
}
that's the view
<c:forEach items="${resultList}" var="item">
<li><c:out value="${item.getUrl()}"/></li>
</c:forEach>
Result class is a inner class:
public class GoogleResults {
private ResponseData responseData;
public ResponseData getResponseData() {
return responseData;
}
public void setResponseData(ResponseData responseData) {
this.responseData = responseData;
}
public String toString() {
return "ResponseData[" + responseData + "]";
}
static class ResponseData {
private List<Result> results;
public List<Result> getResults() {
return results;
}
public void setResults(List<Result> results) {
this.results = results;
}
public String toString() {
return "Results[" + results + "]";
}
}
static class Result {
public String url;
private String title;
public String getUrl() {
return url;
}
public String getTitle() {
return title;
}
public void setUrl(String url) {
this.url = url;
}
public void setTitle(String title) {
this.title = title;
}
public String toString() {
return "Result[url:" + url + ",title:" + title + "]";
}
}
}
Trace:
ava.lang.NullPointerException javax.el.BeanELResolver.invoke(BeanELResolver.java:159) org.apache.jasper.el.JasperELResolver.invoke(JasperELResolver.java:147) org.apache.el.parser.AstValue.getValue(AstValue.java:157) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
The class Result
should be marked as public