0

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)

6
  • Use <c:out value="${item.url}"/> Commented Oct 2, 2014 at 14:08
  • interesting I got that javax.el.PropertyNotFoundException: Propiedad 'url' no legible para el tipo com.leanupp.researcher.GoogleResults$Result Commented Oct 2, 2014 at 14:14
  • Result is a static inner class some problem with that? Commented Oct 2, 2014 at 14:14
  • 1
    Can you show in the question how it looks like? Commented Oct 2, 2014 at 14:16
  • 1
    As the class is not public, maybe the problem is that it is simply not accessible Commented Oct 2, 2014 at 14:17

1 Answer 1

3

The class Result should be marked as public

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.