Casting to superclass JSTL
829153Jan 6 2011 — edited Jan 8 2011Hi all,
I'm try to explain the scenario of the problem.
I have a jsp that receive in the request (from a spring controller) an object called queryResponse type QueryResponseWrapper that have just one property queryResponse type org.apache.solr.client.solrj.response.QueryResponse with getter and setter method.
On the jsp I have :
<c:forEach items="${queryResponse.results}" var="solrDocument" varStatus="status" >
........
</c:forEach>
"results", the property over i do the iteration, is not actually a property but a method called getResults with no argument that return a collection of object type SolrDocumentWrapper that extend another class SolrDocument.
In the class SolrDocumentWrapper have the method getHighlightingData with no arguments.
The problem is, inside the above for-each,
when I try in jstl to access to property of the object SolrDocument I have the data on the page
${solrDocument.content}
but
not when I try to access to property of the SolrDocumentWrapper class.
${solrDocument.highlightingData}
Seams to be that the object that I'm accessing is up-casted.
After that I found that problem I tried, just for a test, to override in the object SolrDocumentWrapper the toString method
@Override
public String toString(){
return this.highlightingData.toString();
}
a that point if I change my jsp to
<c:forEach items="${queryResponse.results}" var="solrDocument" varStatus="status" >
${solrDocument}
</c:forEach>
and I had the toString of the property highlightingData on the page.
{content=[ BASIC TEXT ]}
I tried to do do my best to explain the problem .....
Can anyone help me to understand why?
Thank you in advance.
Alessandro