Skip to main content
Oct 16, 2015 2:28 AM UTC
Solved

Create a target component programmatically

Hi,

I would like to create a target component (sling:resourceType should be cq/personalization/components/target) programmatically.

My scenario is as follows:

- I have a par component_A that has a rendering file component_A.html. This HTML render file calls a JSP file  using the following sightly statement

<sly data-sly-include="componentCreator.jsp" data-sly-unwrap />

- the included "componentCreator.jsp" should then create a target component and pass it to component_A

Does anybody know how to achieve this? Any help would be appreciated.

Regards, Abou

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
Oct 16, 2015 2:28 AM UTC

add a node with a sling:resourceType 'cq/personalization/components/target' programatically similar to other nodes. This creates a target component

Under this, you can create a node by name 'default' with the sling:resourceType mapping to your component would get the default content to it.

4 replies

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
Oct 16, 2015 2:28 AM UTC

add a node with a sling:resourceType 'cq/personalization/components/target' programatically similar to other nodes. This creates a target component

Under this, you can create a node by name 'default' with the sling:resourceType mapping to your component would get the default content to it.

Translate
Oct 16, 2015 2:28 AM UTC

Hi Opkar,

the business requirement is to place target components on dynamically generated websites and then later decide via business logic if a special offer should be displayed at the target component or not.

The main reason why i need this functinality is that the websites are generated automatically and contains several <div> elements in which a special offer can be displayed or not according to a current campaign.

Thanks in advance for your help

Translate
Oct 16, 2015 2:28 AM UTC
        Thank you bsloki. I know the manual way you describe in your answer. But my question is how to create a target component programmatically using Java Code? Regards
Translate
Adobe Employee
Oct 16, 2015 2:28 AM UTC

Hi Abdoulaye,

what you have provided above is the technical requirements. What are you business requirements for this functionality?

Regards,

Opkar

Translate