Skip to main content

Posts

OSGI Component and Services

Component are those classes which are marked with @Component annotation and whose life cycle is managed by felix.  A component is an active participant in the OSGi system , a component can be reinitialized through osgi properties through the methods annotated in the class using the activate and deactivate methods. In order to mark class as component in  aem ecosystem provide @component annotation provided through java package "org.apache.felix.scr.annotations.Component".Please refer the example below. Code sample are for illustration purpose only Following are annotation used are some of basic annotation which should always be used while you are creating component. @label-This is generally used as a title for the object described by the meta type. @description-This is generally used as a description for the object described by the meta type. @metatype-If marked as true it will create a metatype.xml within meta type folder in meta-inf folder in bundl...

Handle bar & AEM server side integration

In AEM 6.0 version, as part of social communities’ project AEM implemented a handlebar script files in place of JSP scripts.  As part of this project AEM SCF community implemented a handle bar engine which in turn uses handlebars.java(jknack) library to compile and execute handlebar templates. Example: Let’s say I have a component called helloworld and the path of component  is  /apps/mysite/components/content/helloworld. Below three steps we need to do to implement header component. 1.       Register a HBS component To register HBS component we need to implement SocialComponentFactory interface and then we need to override methods. In “getSupportedResourceType” method we need to return component path to register it to handlebar engine.  Once we register a component json response will automatically available to handlebar script file. Example: The key aspect is to overri...

Using SlingModel

Sling Model are excellent way to Map your resources to Class or Interface. Many of us has  worked in  ORM frameworks (Hibernate, Ibatis...) ,where we maintain a direct mapping between the data fields and plain old java object class either through annotation or through configuration file.We can achieve the same functionality where we can map resources directly POJO/Interface using Sling Model capability, It is purely annotation driven and creating a Sling Model is quite simple , we need to add @Model class level annotation , with adaptable type specified.The annotation can be applied to either class or interface. Each field or method to be used in injected by Sling Model are annotated with @Inject annotations. As there support for both Interface and Class , we can use it as per the requirement ,mostly interface based sling model would suffice with less code. How to pass parameters to Sling Model Sling Model offers the flexibility to passing ...
How to create  help  button in dialog in AEM/CQ. In our project we have to create Authoring Guide for each of the components developed .All the Authoring elements required a help button to be incorporated in each of the dialog's. AEM provide's this feature oob , we can provide an help button on dialog's on click of this button provide the target  to page to be opened in the property. Solution 1.Login to CRX  de. 2.Create a Component 3.Create Dialog within the Component 4.Create a property in the Dialog "helpPath" the type should be String and give value any existing page path , clicking of the help button should open the page in the window.

How to remove hardcoding .html from pathfield in AEM/CQ

In our project we have a pathfield in quite a lot of dialog for various custom components which refers/links to pages. After getting the value of this pathfield in the sightly template we were  adding the html extension manually on it. e.g.                 <a class="navbar-brand" href="${properties.homepagePath @ context='unsafe'}">${properties.headerAuthTitle}</a> We can avoid hardcoding the path by adding property in dialog link  linkPattern The  pathfield  xtype has a config option called  linkpattern . This allows you to configure the widget to automatically add an extension  in case the browsefield is used  to select the link. If a user types the text , the extension is not added. Use this option to add '.html' and all internal links will have .html appended (assuming the content authors always use the pathfield's browse option to select the link [which they should be doing ] ). This wa...