I have a JSP where I'm trying to use JSTL tags to display data from an in-memory instance of a class. The data consists of a series of Strings where each String is the address of an RSS feed.
In the JSP, I have the following code:
<table border = "1">
<tr>
<c:forEach var = "rssFeedURL" items = "${rssfom.rssFeedURLs}">
<td align = "left">${rssFeedURL}</td>
</c:forEach>
</tr>
</table>
Basically, rssfom is an instance of the following class:
public class RSSFeedOccurrenceMiner extends RSSFeedMiner {
private HashMap<String, Counter> keywordFrequencies;
public RSS_Feed_OccurrenceMiner() {
super();
this.keywordFrequencies = new HashMap();
}
...
}
This inherits from class RSSFeedMiner which contains the following variable and methods:
private ArrayList<String> rssFeedURLs;
public ArrayList<String> getRSSFeedURLs() {
return rssFeedURLs;
}
public void setRSSFeedURLs(ArrayList<String> rssFeedURLs) {
this.rssFeedURLs = rssFeedURLs;
}
So in the JSP, I thought I would be able to use the code above but when the page is run, I simply receive an empty table. And in the server logs, I tend to find message:
javax.el.PropertyNotFoundException: Property 'rssFeedURLs' not found on type RSSFeedOccurrenceMiner
Which is correct given my use of inheritance. So can anyone tell me if JSTL allows inheritance or is there something missing in my code?
I really don't want to use a scriptlet in the JSP.
If the property name starts with two or more subsequent capitals, then it should be accessed like that in EL as well. So, to access the getter
getRSSFeedURLs()
you need${rssfom.RSSFeedURLs}
.That's specified in JavaBeans Spec as well.
The JSP EL (Expression Language, those
${}
things) adheres the JavaBeans Spec. This is thus not specifically related to JSTL (those<c:xxx>
tags).My VO has a following code
When I am trying to access it in a jsp page as below, it is giving following error javax.el.PropertyNotFoundException: Property 'Id' not found on type DocumentPolicyVO
Please anybody can explain the reason.
Your getter method doesn't follow the JavaBeans naming convention. It should be named
getRssFeedURLs
(even if you have an acronym, it should be capitalized like a regular word). In EL, when you specify a property name, it actually ends up calling the getter for that property. To figure out the name of the getter, it capitalizes the first letter in the property name that you have provided (sorssFeedURLs
gets converted toRssFeedURLs
) and tacks onget
to the front of it. So you end up withgetRssFeedURLs
. However, you have named your method asgetRSSFeedURLs
. Java can't find the method and so you get aPropertyNotFoundException
exception.If you don't name your getters right, you cannot access them with EL.