What is the purpose of the star resource path?
Asked Answered
S

1

5

Adobe AEM parsys component renders all children resources and if the WCM mode is set to the appropriate value, it displays Drop component section, which can be used to add new paragraphs. Implementation of the Drop component section is quite strange - it's embedded as a separate component with <cq:include> tag, but the path parameter is set to * (star):

<cq:include path="*" resourceType="<%= newType %>"/>

(newType is a Java variable set before this line).

What happens here? What is the purpose of this star?

Stasiastasis answered 21/11, 2014 at 15:13 Comment(0)
S
9

Sling provides a way to automatically create a resource name. If you send a POST request to an URL ending with a /*, Sling will generate the resource name, using a number of rules described in the documentation.

If you intercept the request sent to the /* resource in servlet or filter and invoke the request.getResource() method, you'll get a StarResource object. It extends the SyntheticResource type, representing resources that doesn't have appropriate node in the JCR. Its resource type is sling:syntheticStarResource, you can call its getParent() method, but generally it isn't very useful. An attempt to adapting it to ValueMap will fail. Sling provides a helper method that checks if the given Resource is a StarResource.

In case of the paragraph system implementation mentioned in the question, the author of the code probably wanted to display the Drop component using a synthetic resource and providing * as the path is the easiest way to do it. You can also be sure that the resource will always be synthetic, as it's impossible to create a node with this name.

Stasiastasis answered 21/11, 2014 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.