If we had component resource set up as such:
We can Assume it will work as such:
Also in a servlet we might be able to do something like
Resource myResource = resourceResolver.getResource(request, "path/to/mycomponent");
I'm just curious how I might be able to get the .json representation in a servlet context as well.
I've done something that sort of solves this, but I was wondering if there was an alternate way, as this solution has huge limitations. Basically I load the Node at the path and do JSONDumps of the Node and it's children. This would allow me to get a larger set of JSON from the resource at the mycomponent.getPath(), but it doesn't allow me the ability to pull the custom JSON view i've created via mycomponent.JSON.jsp.
any thoughts/advice would be great, thank you.
To capture the output of rendering a resource you can use the SlingRequestProcessor
service, which makes a request internally without going through the network layers but still using all the same rendering mechanisms that are used to process HTTP requests.
If you just need to include such output in the rendering that you are computing you can use Request.getRequestDispatcher(somePathWithJsonExtension).include(request, response)
which is what the Sling and CQ include JSP tags do.
Using resourceResolver.getResource(...)
does not do any rendering, it just provides a raw Resource which is a data/content object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With