I don't think there is any way to initialize it in tag it self. That logic should go in component it self. But it is nice to have feature, Provided that you know exact property name used in that component.

I know that <cq:include> tag does not allow such initialization. However I am looking for any alternate programatic way to achieve this.

I think we should be able to invoke the same APIs that are used when we edit a specific component property interactively from the UI.

E.g. Authors edit the Text component and specify the value they want to display in that Text component. Whatever API calls are made behind the scenes to achieve this should be available to us in the component script. I just don't have any insight into CQ Java API programming.

Also after statement currentNode.setProperty("mypropname", "myservicedata") ; do currentNode.save(); so that it will save data to current node.

Now to answer your next question, there are two things and depends on what you want.

1. If you want to display some default value to some field in component lets take above example for foundation/components/text component then set "defaultValue" property at node "/libs/foundation/components/text/dialog/items/tab1/items/text" with what ever value you want to display.

2. If you only want to display default value only at time of component rendering on page then as yogesh mentioned above you have to handle in scriptlet code of that component (as there is not OOTB support through default cq:include taglib or either you customize it locally)

Normally for this use <cq:text property="propName1" placeholder="Lorem ipsum dolor sit amet "/> where place holder will be default value at the time of display.

I will try using the currentNode.save() after setting the properties. I couldn't find any handy documentation (or code snippet) around manipulation of JCR nodes in CQ repository. It would be nice if Adobe provided any code sample demonstrating the node updates (ACL implications, transactions, etc)

I am aware of the defaultValue property but it needs to be set by the developer in CRXDE and it will be fixed for all instances of that component. What I need is the ability to initialize the component property dyanmically per instance of that component. I will try with the placeholder option you mentioned. I had seen that in documentation but did not try out.

I am new to CQ and don't know when to write custom servelets and how to plug them in. Is there any document explaining the development process using CQ Java APIs? E.g. How do I know the organization and life cycle of CQ objects? Also I see a component interface which does not have any setter methods. It is not obvious that we need to refer the component as node and then call set property on it.

I hope you have considered above suggestion. After looking at you next reply i can suggest using design_dialog in component design. design_dialog helps you to configure any property that you want to set once at template level (using any of the page) and will be shared accross all the pages using same template. Now it will help you to meet your second requirement about having different value but that will be based on template level so when you change template you can configure same property with new value.

Using design dialog won't help me as I am using the same template for my pages. The template will have a component that dynamically pulls some data from a backend system. I want authors to provide an ID for which data to be pulled from backend. The component will then fetch the corresponding data from backend service and populate it in my custom text components (inherited from CQ text component).

Depending on the ID provided the service may return different number of data items and for each of them my component will use add text components. Authors can later edit these text components to add more data or formatting as needed

You should *not* do this per request. Instead, have a scheduled job which accesses the external service on a periodic basis and populates the components. This job will run as a privledged user who can set properties. Assuming that anyone loading a page will have the rights to edit that page's properties (or the properties of components in that page) is not a safe assumption.

I am actually interetsed in knowing if there is any way in Adobe CQ to dynamically initialize component properties at the time of inclusion.

E.g. <cq:include path="mypath" resourceType="my-component-path"/> I need to set my-component.my-property to some value while including it on the page. It may or may not be user editable component. I am OK to write Java/JSP code that may deal with Node objects instead of using <cq:include> if that allows me to do what I need.

If you do <cq:include path="mypath" resourceType="my-component-path"/> and mypath doesn't exist, a synthetic resource is created with the provided resource type. There's not currently a way to provide additional properties. You could write your own tag to do that. The source for the sling:include tag is available. I don't think the JCR API wouldn't be used as you aren't talking about persisting anything.

It's generally a bad idea to have components impacted by their container. This reduces flexibilty and is usually a sign that the (child) component isn't really independent of the parent. Where it is necessary (which again, is rare), the parent passes information to the child via request attributes.