Thursday, 26 February 2015

Maven-Scr-Plugin Error in AEM

In this blog, I will explain an error occurred when we build an AEM project using -

mvn clean install -P <Profile Name>, maven command.

Error description is as shown below - 

[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) on project blog-bundle: SCR Descriptor parsing had failures (see log) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command


[ERROR]   mvn <goals> -rf :blog-bundle

Cause of this error - 

Most of the time this error occur because of the use of these two annotations - 
@SlingServlet & @Component same class.


For Example, If your coding syntax is  - 

@SlingServlet(path="/bin/blog" extension="html")
@Component
Class TestServlet extends SlingSafeMethodsServlet { /*  ----------------------- */ }

In this case you will get that error, because @SlingServlet have a property "generateComponent" by default it's value is "true" so ideally you don't provide the @Component annotation.

How to Resolve this issue - 

There are two ways to resolve this issue - 

1). Remove @Component annotation while creating Sling Servlet.

2). The issue with first solution are - 

2.1). We are not able to activate this Sling Servlet immediately, It is totally dependent on Felix implementation when it will activate this Sling Servlet. i.e. it may or may not be in active state after deploying the package.

2.2). We are not able to use immediate, enabled metatype & other properties provided by  @Component

preferred way to use these annotations is -

@SlingServlet(path="/bin/blog" extension="html", generateComponent=false)
@Component
Class TestServlet extends SlingSafeMethodsServlet { /*  ----------------------- */ }






Happy Coding
Namah Shivay

Sunday, 8 February 2015

Image not visible on Dialog reopen in AEM

In this post, I am going to sort out a very interesting problem which is occured when we use image component as a tab in out custom component.
Most of time when we want to add a image tab into our component then we use these properties - 
                         path -  /libs/foundation/components/page/tab_image.infinity.json
                        xtype -  cqinclude
Using this properties we are able to add a new tab that provides you a  drag & drop or upload a image functionality in your component. Some developers uses another approach to add a image tab in our component using xtype smatimage. 
Both of these approaches works fine for us but some time we face an issue with these component dialogs. 

Problem Statement - 
when we drop a image on this image tab & click on ok button, we are able to see this image as our component desired functionality, till now everything is working fine. Now when we reopen the dialog & open the image tab, image will not be displayed. i.e. when we reopen component dialog image tab it's not displayed here.

How to resolve this issue - 
1). Check sling:resourceSuperType property on your component, it must be present.
2). sling:resourceSuperType property value must be foundation/components/page. 
3). Open your component's .content.xml file and check <jcr:root> tag, here xmlns:sling must be present, for example in my case it is - 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root 
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"    
    xmlns:cq="http://www.day.com/jcr/cq/1.0" 
    xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:description="Jcr Description."
    jcr:primaryType="cq:Component"
    jcr:title="Test Component"
    sling:resourceSuperType="foundation/components/page"
    allowedParents="[*/parsys]"
    componentGroup="Test"
/>

The above schema work fine as both of these property are there. After defining these two highlighted properties, test you component & I am damn sure, you component will start functioning properly. 



Happy Coding
Namah Shivay