So its not something you have to do programatically but its component design. Every time when you author any component (using "dialog") via drag and drop the component on page (creating instance at page level) or directly including component using code (template level) it associates information to individual page but when you author component using design_dialog it associates information at template level and share to all pages.
To achieve common sharing at all pages (template level) you have to add design_dialog (similar to dialog you can design) node at your component and then you can author it via going to page design mode (from sidekick at the bottom bar).
1. /libs/foundation/components/title component which will give you idea about how you can design the component using design_dialog and it will also have code to how to fetch data information which set at design level (template level)
2. http://dev.day.com/docs/en/cq/current/howto/components_develop.html to understand more about design dialog.
Let me know if it doesn't help you.
Thanks for the clarification Rush. I'm aware of the design of the dialog and design dialog for components. However i'm in this situation where i am adding dynamic amount of the same component into a page.
How i am achieving this is something like
String includePath = "mycomponentname_" + i;
<cq:include path="<%=includePath%>" resourceType="cx/components/mycomponent" />
However the components that are dynamically added do not seem to share the design dialog as compared to when drag and drop the components in manually. Am i doing the dynamic include of the components wrongly ?
So here is the thing which i can think of by above example you are missing. Design dialog is specific to component instance but share accross pages which are using same template. what does that mean is if you are adding multiple instance of same component (on page) then each instance will have it own separate design dialog configuration (sets at template level) but when you configure this design dialog on one page of that template then all other pages (using same template) will share same design configuration info corresponding to each component instance.
I hope it clarifies your doubt about component instance design configuration. Let me know for more information.