Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Looking for information to create a custom JSON rendering

Avatar

Level 1

I need to create a rendering that is very similar to page.infinity.json, only mine would not include any jcr and cq fields.

Any links to information on this would be appreciated, I'm not having much luck finding what I need.

Thanks,

Doug

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can create a Sling Servlet and bind it with the resourceType of your basepage component (assuming you already have basepage component for all page components) along with resourceType binding, you can also specify your custom selector (like .infinity) and extension as .JSON.

Doing so, now using your servlet, you can create any JSON response that you need.

Refer to following link to know more about binding servlet to resourcetype - https://sling.apache.org/documentation/the-sling-engine/servlets.html#example-registration-by-resour...

Also there was recently a query raised on binding servlet to resourceType, kindly refer that as well - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

Hope it helps.

Cheers

- Runal

View solution in original post

5 Replies

Avatar

Correct answer by
Community Advisor

You can create a Sling Servlet and bind it with the resourceType of your basepage component (assuming you already have basepage component for all page components) along with resourceType binding, you can also specify your custom selector (like .infinity) and extension as .JSON.

Doing so, now using your servlet, you can create any JSON response that you need.

Refer to following link to know more about binding servlet to resourcetype - https://sling.apache.org/documentation/the-sling-engine/servlets.html#example-registration-by-resour...

Also there was recently a query raised on binding servlet to resourceType, kindly refer that as well - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

Hope it helps.

Cheers

- Runal

Avatar

Level 1

Still struggling a bit - just trying to create a sling servlet has been problematic.  I followed Scott's write up, but I keep running into errors.  I believe they may be related to OS and app versions.

Do you know of any other examples to create a servlet and maybe some code samples for accomplishing a custom selector/rendering?

Avatar

Level 2

Another way to do this creating custom format JSP instead of servlet. For the require page component add the additional format  like below.

/apps/sample/components/article/

----article.jsp

----article.json.jsp. 

In the json jsp get the current node and traverser and build the json in the required format. Make sure to set the response content type to JSON as below.

response.setContentType("application/json");

This will mask the default json format for this template. If you wish not to we can specify another custom format 

Avatar

Level 10

Is this the write you are referring to:

https://helpx.adobe.com/experience-manager/using/resourcetypes.html

There is a package too with this.

There has been quite a few community members that have got this working. I want to know if this works for you and if not - why. 

Does the package work. Try installing the package. If it does not work- let me know. I can setup a connect session to get to the bottom of why this content is not running within your environment. 

Avatar

Level 10

This one just returns HTML:

[img]html.png[/img]

YOu can code the servlet to return JSON data.