In some component JSP scripts, I see code similar to
<sling:include resource="<%= par %>" />
In which par is a Paragraph object.
According to the API docs for Paragraph, the toString() method simply "returns a human readable string representation of this resource."
The question, then, is why is this string representation of the Paragraph instance passed to <sling:include>? And what is the general format of the string returned by Paragraph.toString()?
Solved! Go to Solution.
Views
Replies
Total Likes
The resource attribute of sling:include accepts either a path to a resource or a org.apache.sling.api.resource.Resource object. The com.day.cq.wcm.foundation.Paragraph class implements the org.apache.sling.api.resource.Resource. So in the code about the toString on the Paragraph object isn't being called, it's actually passing in the Paragraph object which the tag accepts because it implements the Resource interface.
Views
Replies
Total Likes
The resource attribute of sling:include accepts either a path to a resource or a org.apache.sling.api.resource.Resource object. The com.day.cq.wcm.foundation.Paragraph class implements the org.apache.sling.api.resource.Resource. So in the code about the toString on the Paragraph object isn't being called, it's actually passing in the Paragraph object which the tag accepts because it implements the Resource interface.
Views
Replies
Total Likes
I now remember. But that was the prehistoric way of passing objects to tags. I wonder why the built-in JSPs do not use JSP EL (e.g. ${par}) to pass variables to tags.
Views
Replies
Total Likes
Views
Likes
Replies