Expand my Community achievements bar.

SOLVED

org.apache.sling.scripting.sightly.SightlyException: Identifier XXXX cannot be correctly instantiated by the Use API

Avatar

Level 3

Hi,

I am trying install my AEM 6.1 project on AEM 6.3. After installation and update of all POM, related code, i am able to open my project webpages. However when trying to drag and drop any component on to a sample page using my project template its failing with below exception.

13.11.2017 09:45:46.050 *ERROR* [0:0:0:0:0:0:0:1 [1510537544955] GET /content/singtel/en/Test6_3/jcr:content/par/sd_component_dualima.html HTTP/1.1] com.day.cq.wcm.core.impl.WCMDebugFilter Error during include of SlingRequestPathInfo: path='/content/singtel/en/Test6_3/jcr:content/par/sd_component_dualima', selectorString='null', extension='html', suffix='null'

org.apache.sling.scripting.sightly.SightlyException: Identifier com.singtel.springd.aem.components.singtel.dualimagecomponent.DualImageComponentController cannot be correctly instantiated by the Use API

at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:77)

at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:75)

at org.apache.sling.scripting.sightly.apps.springd.components.global.componentTemplate_html$1.render(componentTemplate_html.java:83)

at org.apache.sling.scripting.sightly.java.compiler.RenderUnit.render(RenderUnit.java:48)

at org.apache.sling.scripting.sightly.java.compiler.RenderUnit.callUnit(RenderUnit.java:85)

at org.apache.sling.scripting.sightly.apps.springd.components.global.singtel.sd__002d__component__002d__dualimage__002d__singtel.html_html.render(html_html.java:46)

at org.apache.sling.scripting.sightly.java.compiler.RenderUnit.render(RenderUnit.java:48)

at org.apache.sling.scripting.sightly.impl.engine.SightlyCompiledScript.eval(SightlyCompiledScript.java:61)

at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:386)

at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:184)

at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:491)

at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552)

at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:77)

at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilterWithErrorHandling(WCMDebugFilter.java:192)

at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:159)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:278)

at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:373)

at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:190)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:96)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:282)

at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:71)

at com.day.cq.wcm.core.impl.warp.TimeWarpFilter.doFilter(TimeWarpFilter.java:109)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.cq.social.ugcbase.security.impl.SaferSlingPostServlet.doFilter(SaferSlingPostServlet.java:114)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler.doFilter(AdhocAssetShareAuthHandler.java:436)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.dam.core.impl.servlet.ActivityRecordHandler.doFilter(ActivityRecordHandler.java:154)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:73)

at com.adobe.granite.rest.impl.servlet.ApiResourceFilter.doFilter(ApiResourceFilter.java:70)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.granite.requests.logging.impl.RequestLoggerImpl.doFilter(RequestLoggerImpl.java:126)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter.doFilter(AssetContentDispositionFilter.java:96)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.granite.csrf.impl.CSRFFilter.doFilter(CSRFFilter.java:217)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.security.impl.ContentDispositionFilter.doFilter(ContentDispositionFilter.java:180)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl.doFilter(AuthoringUIModeServiceImpl.java:367)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter.doFilter(RedirectFilter.java:248)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.singtel.springd.aem.filters.LoggingFilter.doFilter(LoggingFilter.java:36)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:107)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.cq.social.commons.cors.CORSAuthenticationFilter.doFilter(CORSAuthenticationFilter.java:91)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.wcm.foundation.forms.FormsHandlingServletHelper.handleFilter(FormsHandlingServletHelper.java:221)

at com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.doFilter(FormsHandlingServlet.java:138)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.granite.optout.impl.OptOutFilter.doFilter(OptOutFilter.java:76)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.wcm.foundation.forms.FormsHandlingServletHelper.handleFilter(FormsHandlingServletHelper.java:221)

at com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet.doFilter(CoreFormHandlingServlet.java:131)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.singtel.springd.aem.servlets.filter.ServletAuthenticationFilter.doFilter(ServletAuthenticationFilter.java:149)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.day.cq.wcm.core.impl.WCMRequestFilter.doFilter(WCMRequestFilter.java:90)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.cq.history.impl.HistoryRequestFilter.doFilter(HistoryRequestFilter.java:122)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.cq.mcm.campaign.servlets.CampaignCopyTracker.doFilter(CampaignCopyTracker.java:100)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:83)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:81)

at com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:60)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:138)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:73)

at com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl.doFilter(ResourceResolverHelperImpl.java:83)

at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

at org.apache.sling.engine.impl.SlingRequestProcessorImpl.doProcessRequest(SlingRequestProcessorImpl.java:151)

at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:219)

at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:85)

at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:79)

at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:308)

at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:96)

at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:295)

at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:138)

at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

at org.apache.sling.featureflags.impl.FeatureManager.doFilter(FeatureManager.java:116)

at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:72)

at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:128)

at org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)

at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)

at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)

at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)

at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)

at org.eclipse.jetty.server.Server.handle(Server.java:499)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)

at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)

at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)

at java.lang.Thread.run(Thread.java:745)

Caused by: org.apache.sling.models.factory.MissingElementsException: Could not inject all required fields into class com.singtel.springd.aem.components.singtel.dualimagecomponent.DualImageComponentController

at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:593)

at org.apache.sling.models.impl.ModelAdapterFactory.internalCreateModel(ModelAdapterFactory.java:335)

at org.apache.sling.models.impl.ModelAdapterFactory.createModel(ModelAdapterFactory.java:223)

at org.apache.sling.scripting.sightly.models.impl.SlingModelsUseProvider.provide(SlingModelsUseProvider.java:126)

at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:72)

... 122 common frames omitted

Suppressed: org.apache.sling.models.factory.MissingElementException: Could not inject private org.apache.sling.api.resource.Resource com.singtel.springd.aem.components.singtel.dualimagecomponent.DualImageComponentController.imageDesktop

at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:598)

... 126 common frames omitted

Caused by: org.apache.sling.models.factory.ModelClassException: No injector returned a non-null value!

at org.apache.sling.models.impl.ModelAdapterFactory.injectElement(ModelAdapterFactory.java:513)

at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:596)

... 126 common frames omitted

Suppressed: org.apache.sling.models.factory.MissingElementException: Could not inject private org.apache.sling.api.resource.Resource com.singtel.springd.aem.components.singtel.dualimagecomponent.DualImageComponentController.imageMobile

at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:598)

... 126 common frames omitted

Caused by: org.apache.sling.models.factory.ModelClassException: No injector returned a non-null value!

at org.apache.sling.models.impl.ModelAdapterFactory.injectElement(ModelAdapterFactory.java:513)

at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:596)

... 126 common frames omitted

Below is my core POM.xml file

<?xml version="1.0" encoding="UTF-8"?>

<!--

|  Copyright 2015 Adobe Systems Incorporated

|

|  Licensed under the Apache License, Version 2.0 (the "License");

|  you may not use this file except in compliance with the License.

|  You may obtain a copy of the License at

|

|      http://www.apache.org/licenses/LICENSE-2.0

|

|  Unless required by applicable law or agreed to in writing, software

|  distributed under the License is distributed on an "AS IS" BASIS,

|  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

|  See the License for the specific language governing permissions and

|  limitations under the License.

-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>

        <groupId>com.singtel.springd.aem</groupId>

        <artifactId>aem-parent</artifactId>

        <version>1.14.49-SNAPSHOT</version>

        <relativePath>../pom.xml</relativePath>

    </parent>

    <artifactId>aem-parent.core</artifactId>

    <packaging>bundle</packaging>

    <name>SpringDigital - AEM - Core</name>

    <description>Core bundle for SpringDigital - AEM</description>

    <build>

        <testResources>

            <testResource>

                <directory>${project.basedir}/src/test/resource</directory>

            </testResource>

        </testResources>

        <plugins>

<plugin>

                <groupId>org.apache.sling</groupId>

                <artifactId>maven-sling-plugin</artifactId>

            </plugin>

            <plugin>

                <groupId>org.apache.felix</groupId>

                <artifactId>maven-scr-plugin</artifactId>

            </plugin>

            <plugin>

                <groupId>org.apache.felix</groupId>

                <artifactId>maven-bundle-plugin</artifactId>

                <extensions>true</extensions>

<executions>

                    <execution>

                        <id>bundle-manifest</id>

                        <phase>process-classes</phase>

                        <goals>

                            <goal>manifest</goal>

                        </goals>

                    </execution>

                </executions>

<configuration>

                    <instructions>

                    <Embed-Dependency>

                            commons-lang3,jsoup,jackson-core,poi,jackson-databind,jackson-annotations,aws-java-sdk-dynamodb,

                            aws-java-sdk-s3,aws-java-sdk-core,commons-logging,httpclient,httpcore,joda-time,json-simple,commons-httpclient,geronimo-atinject_1.0_spec

                        </Embed-Dependency>

                        <!-- Import any version of javax.inject, to allow running on multiple versions of AEM -->

                        <Import-Package>javax.inject;version=1.0.0,com.adobe.cq.sightly,*;resolution:=optional

                        </Import-Package>

                        <Require-Bundle>org.apache.sling.models.api</Require-Bundle>

                        <Sling-Model-Packages>

                            com.singtel.springd.aem,

                            com.singtel.springd.aem.datasource.impl

                        </Sling-Model-Packages>

                    </instructions>

                </configuration>

            </plugin>

        </plugins>

    </build>

    <profiles>

        <!-- Development profile: install only the bundle -->

        <profile>

            <id>autoInstallBundle</id>

            <activation>

                <activeByDefault>false</activeByDefault>

            </activation>

            <build>

                <plugins>

                    <plugin>

                        <groupId>org.apache.sling</groupId>

                        <artifactId>maven-sling-plugin</artifactId>

                        <configuration>

                            <!-- Note that this requires /apps/springd/install to exist!!       -->

                            <!-- This is typically the case when ui.apps is deployed first      -->

                            <!-- Otherwise, create /apps/springd/install manually (CRXDE|Lite)  -->

                            <slingUrlSuffix>/apps/springd/install/</slingUrlSuffix>

                            <failOnError>true</failOnError>

                        </configuration>

                    </plugin>

                </plugins>

            </build>

        </profile>

    </profiles>

    <dependencies>

        <!-- OSGi Dependencies -->

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr.annotations</artifactId>

        </dependency>

        <dependency>

            <groupId>biz.aQute</groupId>

            <artifactId>bndlib</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.cmpn</artifactId>

        </dependency>

<dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.annotation</artifactId>

        </dependency>

        <!-- Other Dependencies -->

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-api</artifactId>

        </dependency>

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-simple</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.jcr</groupId>

            <artifactId>jcr</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.servlet</groupId>

            <artifactId>servlet-api</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.api</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.models.api</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.models.impl</artifactId>

        </dependency>

<dependency>

        <groupId>org.apache.geronimo.specs</groupId>

        <artifactId>geronimo-atinject_1.0_spec</artifactId>

    </dependency>

        <dependency>

            <groupId>com.adobe.aem</groupId>

            <artifactId>uber-jar</artifactId>

            <classifier>apis</classifier>

        </dependency>

        <dependency>

            <groupId>javax.mail</groupId>

            <artifactId>mail</artifactId>

        </dependency>

        <!-- dependency>

            <groupId>javax.inject</groupId>

            <artifactId>javax.inject</artifactId>

        </dependency-->

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

        </dependency>

<dependency>

            <groupId>org.mockito</groupId>

            <artifactId>mockito-core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.mockito</groupId>

            <artifactId>mockito-all</artifactId>

        </dependency>

        <dependency>

            <groupId>junit-addons</groupId>

            <artifactId>junit-addons</artifactId>

        </dependency>

        <dependency>

            <groupId>com.adobe.acs</groupId>

            <artifactId>acs-aem-commons-bundle</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.commons</groupId>

            <artifactId>commons-lang3</artifactId>

        </dependency>

        <dependency>

            <groupId>org.jsoup</groupId>

            <artifactId>jsoup</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.httpcomponents</groupId>

            <artifactId>httpclient</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.testing.sling-mock</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.jackrabbit</groupId>

            <artifactId>jackrabbit-jcr-commons</artifactId>

            <version>2.11.0</version>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>org.apache.jackrabbit</groupId>

            <artifactId>jackrabbit-jcr2dav</artifactId>

            <version>2.5.1</version>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>org.apache.jackrabbit</groupId>

            <artifactId>jackrabbit-webdav</artifactId>

            <version>2.2.8</version>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>org.powermock</groupId>

            <artifactId>powermock-module-junit4</artifactId>

        </dependency>

        <dependency>

            <groupId>org.powermock</groupId>

            <artifactId>powermock-api-mockito</artifactId>

        </dependency>

        <dependency>

            <groupId>org.powermock</groupId>

            <artifactId>powermock-core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.commons</groupId>

            <artifactId>commons-email</artifactId>

        </dependency>

        <dependency>

            <groupId>commons-collections</groupId>

            <artifactId>commons-collections</artifactId>

        </dependency>

        <dependency>

            <groupId>commons-io</groupId>

            <artifactId>commons-io</artifactId>

        </dependency>

        <dependency>

            <groupId>com.fasterxml.jackson.core</groupId>

            <artifactId>jackson-annotations</artifactId>

        </dependency>

        <dependency>

            <groupId>com.fasterxml.jackson.core</groupId>

            <artifactId>jackson-core</artifactId>

        </dependency>

        <dependency>

            <groupId>com.fasterxml.jackson.core</groupId>

            <artifactId>jackson-databind</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.httpcomponents</groupId>

            <artifactId>httpcore</artifactId>

        </dependency>

        <dependency>

            <groupId>com.amazonaws</groupId>

            <artifactId>aws-java-sdk-s3</artifactId>

        </dependency>

        <dependency>

            <groupId>com.amazonaws</groupId>

            <artifactId>aws-java-sdk-dynamodb</artifactId>

        </dependency>

        <dependency>

            <groupId>com.amazonaws</groupId>

            <artifactId>aws-java-sdk-core</artifactId>

        </dependency>

        <dependency>

            <groupId>commons-logging</groupId>

            <artifactId>commons-logging</artifactId>

        </dependency>

        <dependency>

            <groupId>joda-time</groupId>

            <artifactId>joda-time</artifactId>

        </dependency>

        <dependency>

            <groupId>commons-fileupload</groupId>

            <artifactId>commons-fileupload</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.poi</groupId>

            <artifactId>poi</artifactId>

        </dependency>

        <dependency>

            <groupId>commons-lang</groupId>

            <artifactId>commons-lang</artifactId>

        </dependency>

        <dependency>

            <groupId>com.googlecode.json-simple</groupId>

            <artifactId>json-simple</artifactId>

            <version>1.1</version>

        </dependency>

<dependency>

    <groupId>commons-httpclient</groupId>

    <artifactId>commons-httpclient</artifactId>

</dependency>

    </dependencies>

</project>

My Sling Model, in BaseController, i am adding few padding to each component:-

@Model(adaptables = SlingHttpServletRequest.class)

public class DualImageComponentController extends BaseController {  

  

 

    private static final Integer DEFAULT_DESKTOP_IMG_HEIGHT = 300;

  

    private static final Integer DEFAULT_MOBILE_IMG_HEIGHT = 100;

  

    /**

     *  Full Width property.

     */

    @Inject @Via(ModelConstants.RESOURCE)

    @Optional

    private String fullWidth;

  

    /**

     * Image Desktop Resource.

     */

    @Inject @Via(ModelConstants.RESOURCE)

    private Resource imageDesktop;

  

    /**

     * Mobile Desktop Resource.

     */

    @Inject @Via(ModelConstants.RESOURCE)

    private Resource imageMobile;

  

    /**

     * Returns the model for this component.

     *

     * @return ImageComponentModel.

     */

    public BaseContentModel getModel() {

        final ImageModel largeImage = getDesktopImage();

        final ImageModel smallImage = getMobileImage();

        return ComponentModelBuilder.build(new ImageComponentModel(),

            icm -> icm.setMobile(smallImage),

            icm -> icm.setDesktop(largeImage),

            icm -> icm.setFullWidth(null == fullWidth

                ? false : Boolean.valueOf(fullWidth)));

    }

    /**

     * Returns the image model for Desktop image.

     *

     * @return ImageModel.

     */

    private ImageModel getDesktopImage() {

        final ImageModel largeImage = new ImageModel();

        final ValueMap vm = imageDesktop.getValueMap();

        if (vm != null) {

            largeImage.setAltText(vm.get(ModelConstants.ALT, ""));

            largeImage.setImageSrc(vm.get(ModelConstants.FILE_REFERENCE, ""));

            largeImage.setHeight(((null != vm.get(ModelConstants.IMG_HEIGHT)

                    ? vm.get(ModelConstants.IMG_HEIGHT, Integer.class)

                    : DEFAULT_DESKTOP_IMG_HEIGHT)));

            largeImage.setImagePosition(ModelConstants.EXTRA_CLASS + vm.get(ModelConstants.IMG_POSITION, ""));

        }

        return largeImage;

    }

  

    /**

     * Returns the image model for Mobile image.

     *

     * @return ImageModel.

     */

    private ImageModel getMobileImage() {

        final ImageModel smallImage = new ImageModel();

        final ValueMap vm = imageMobile.getValueMap();

        if (vm != null) {

            smallImage.setAltText(vm.get(ModelConstants.ALT, ""));

            smallImage.setImageSrc(vm.get(ModelConstants.FILE_REFERENCE, ""));

            smallImage.setHeight(((null != vm.get(ModelConstants.IMG_HEIGHT)

                    ? vm.get(ModelConstants.IMG_HEIGHT, Integer.class)

                    : DEFAULT_MOBILE_IMG_HEIGHT)));

            smallImage.setImagePosition(ModelConstants.EXTRA_CLASS + vm.get(ModelConstants.IMG_POSITION, ""));

        }

        return smallImage;

    }

}

Please help.

desktop_exl_promo_600x100_weempoweryou.png

1 Accepted Solution

Avatar

Correct answer by
Level 10

We have AEM 6.3 Sling Model article that works and does not throw NPE. See this -- Creating a custom Touch UI Grid Component for Adobe Experience Manager

import org.apache.sling.api.resource.Resource;

import org.apache.sling.models.annotations.Model;

import org.apache.sling.models.annotations.Optional;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

@Model(adaptables = Resource.class)

public class ColumnControl {

Also - for AEM 6.3 -- MAKE sure you use UBER 6.3 and the dependencies shown in this article!

View solution in original post

6 Replies

Avatar

Level 10

have a look at this in your log "Could not inject all required fields into class ". When you drag and drop a component, all properties will not present in JCR so that it can be injected by sling model.

@Injected fields/methods are assumed to be required. To mark them as optional, use @Optional

Two simple solution:-

1. Use @Optional like

    

     @Inject @Optional

     private String xyz;

2. In case most fields injected fields are optional, change the default Injection strategy to DefaultInjectionStrategy.OPTIONAL like

     @Model(adaptables=Resource.class, defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL)

Avatar

Level 3

hi edubey​, thanks for reply.

in AEM 6.3, do we need to always adapt sling models to Resource ?   All Sling models  written  6.1 project adapts to SlingHttpServletRequest, so do we need to change whole implementation of all Models ? Please suggest

We made mandatory the injection, so that the view won't be rendered unless the dragged component is not authored all mandatory fields.

Avatar

Level 10

in AEM 6.3, do we need to always adapt sling models to Resource ?   All Sling models  written  6.1 project adapts to SlingHttpServletRequest, so do we need to change whole implementation of all Models ? Please suggest

     - As long you don't need access to the adaptables object (in this case SlingHttpServletRequest) , the resource should be fine. I don't see any need to change the whole implementation

We made mandatory the injection, so that the view won't be rendered unless the dragged component is not authored all mandatory fields.

     - but you still have control from sightly for this and making it @optional does not do any harm. Though you have made them mandatory, they don't exist at certain point

Avatar

Level 3

I tried with defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL , but it did not help me. As in code we are reading values from @Inject & @Via ("resource"), its not being available, so failing with NPE.

below is my Model look like.

@Model(adaptables = SlingHttpServletRequest.class,  defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL)

public class DualImageComponentController

@Inject @Via("resource")

    private Resource imageDesktop;

   

   

    @Inject @Via("resource")

    private Resource imageMobile;

then i am doing some operation on imageDesktop & imageMobile.

Any other suggestion would help a lot. Thanks

Avatar

Level 10

AFAIK, you have to take care of NPE from your code, Sling Model won't be doing it.

Also, Since you are aware of NPE, putting a check should fix it and performing operation when you have values available

Thanks

Avatar

Correct answer by
Level 10

We have AEM 6.3 Sling Model article that works and does not throw NPE. See this -- Creating a custom Touch UI Grid Component for Adobe Experience Manager

import org.apache.sling.api.resource.Resource;

import org.apache.sling.models.annotations.Model;

import org.apache.sling.models.annotations.Optional;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

@Model(adaptables = Resource.class)

public class ColumnControl {

Also - for AEM 6.3 -- MAKE sure you use UBER 6.3 and the dependencies shown in this article!