Greetings,
I am facing this error when trying to print on a jsp page the result of a List using beans. See the piece below from class News:
...
public List<NewsBean> getSingleNewsList(){
String sqlStmt;
String [][] results;
singleNewsList = new LinkedList<NewsBean>();
sqlStmt = "SELECT newsid, title, text, source " +
", to_char(publish_date, 'mm/dd/yyyy hh:mi:ss') pbs_date, author FROM it_news " +
" WHERE newsid = " + ID;
results = pullAllRecordsAsString(sqlStmt);
int rows = results[0].length;
NewsBean[] newsBean = new NewsBean[rows];
for(int x = 0; x < rows; x++){
newsBean[x] = new NewsBean();
}
for(int rowPosition = 0; rowPosition < rows; rowPosition++){
newsBean[rowPosition].id = Integer.valueOf(results[0][rowPosition]);
newsBean[rowPosition].title = results[1][rowPosition];
newsBean[rowPosition].text = results[2][rowPosition];
newsBean[rowPosition].source = results[3][rowPosition];
newsBean[rowPosition].publishDate = results[4][rowPosition];
newsBean[rowPosition].author = results[5][rowPosition];
singleNewsList.add(rowPosition, newsBean[rowPosition]);
}
return singleNewsList;
}
...
private List<NewsBean> singleNewsList;
class NewsBean{
int id;
String title;
String text;
String source;
String publishDate;
String author;
public int getId() {
return id;
}
public String getTitle() {
return title;
}
public String getText() {
return text;
}
public String getSource() {
return source;
}
public String getPublishDate() {
return publishDate;
}
public String getAuthor() {
return author;
}
}
...
The jsp piece raising the exception is the following:
<jsp:useBean id="news" class="com.jsptest.Code.News"/>
<td width="81%">
<%news.setID(Integer.parseInt(request.getParameter("newsid"))); %>
<c:forEach var="nws" items="${news.singleNewsList}">
<div style="background: #FFFF99">
<center>
<h2>
<a href="/jspteste/single_news.jsp?newsid=<c:out value="${nws.id}"/>"><c:out value="${nws.id}"/> . <c:out value="${nws.title}"/>
</a>
</h2>
</center>
<h3 align="right"><c:out value="by: ${nws.author} on ${nws.publishDate}"/></h3>
</div>
<hr />
<p align="justify"><font face="Courier New, Courier, monospace"><c:out value="${nws.text}" escapeXml="false"/></font></p>
<hr />
<p align="right">Source: <c:out value="${nws.source}"/></p>
</c:forEach>
</td>
This is very similar to what I use on another page with a also very similar class where it works just fine. Why am I getting this exception "javax.el.PropertyNotFoundException: Property 'id' not readable on type int"? What can I do to resolve it?
Appreciate all your inputs,
Thiago Santana