Reputation: 3
I am getting string objects instead of Person objects in my JSTL.
Here is the code in my .tag file:
<%
List<Person> perList=(List<Person>)pageContext.getAttribute("myVehicles");
HashMap<String, com.info.PersonInfo> personRatingsMap=(HashMap<String, com.info.PersonInfo>)pageContext.getAttribute("personsMap");
com.info.PersonInfo rtg=null;
int i=0;
HashMap<String, Object> givenMap=null;
String tempYear=null;
for(Object obj : perList){
Person currPer=(Person)obj;
tempYear=currPer.getYear();
rtg=personRatingsMap.get(tempYear);
givenMap=mapValuePair.get(tempYear);
if(givenMap!=null){
currPer.getNameset().get("PER").put("fname",givenMap.get("Per_NAME").toString());
currPer.getNameset().get("PER").put("lname",givenMap.get("PerL_NAME").toString());
currPer.getIdset().get("PER").put("myid",givenMap.get("myid").toString());
currPer.setYear(givenMap.get("YEAR").toString());
}
if(rtg !=null){
currPer.setRating(rtg);
}
perList.set(i,currPer);
i++;
}
pageContext.setAttribute("myPersons",perList);
%>
<c:forEach items="myPersons" var="perFromList">
<crp:getModelDefaultPhoto var="defaultPhoto"
makeid="${perID}" modelid="${perIID}"
year="${perFromList.year}" />
<c:if test="${!empty defaultPhoto.value and defaultPhoto.value != ''}">
<c:set target="${photomap}" property="${perFromList.year}" value="${defaultPhoto.name},${defaultPhoto.value}" />
</c:if>
</c:forEach>
I am getting this error:
Unable to find a value for "year" in object of class "java.lang.String" using operator "."
Blockquote
So clearly the foreach loop is returning String instead of Person object because when I put System.out.println code in my scriptlet each Peson has the Year associated with it in the foreach It is considering person as String not the Person object.
I will really appreciate any help on this.
Upvotes: 0
Views: 1035
Reputation: 7305
See if this works:
<c:forEach items="${myPersons}" var="perFromList">
Upvotes: 0
Reputation: 403471
It should be
<c:forEach items="${myPersons}" var="perFromList">
not
<c:forEach items="myPersons" var="perFromList">
Without the ${...}
, you're just operating off the String "myPersons"
, rather than the list that myPersons
represents.
Upvotes: 1