Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Error during include of component - TextModel cannot be correctly instantiated by the Use API

Avatar

Level 5

When attempting to "Insert component", I get the following error:

 

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: identifier com.adobe.oursite.core.models.TextModel cannot be correctly instantiated by the Use API.

 

I'm able to add other components, just not the Text Editor component. There are a few discussions that I found online, but nothing I've tried has resolved the issue. 

 

23 Replies

Avatar

Community Advisor

Hi @Codelime 

This error is thrown when there is an issue with the Sling Model class instantiation. There could be multiple reasons for this type of error.

Can you please put the snapshot of your code to debug further?

 

Thanks!

Avatar

Community Advisor

Hi @Codelime 

You should have the file under com.adobe.oursite.core.models package.

Please check your code base and see if you have the file named TextModel.java

 

Thanks!

Avatar

Level 5
I might have found it. Is this it? \core\src\main\java\com\adobe\business\core\models\TextModel.java

Avatar

Community Advisor

@Codelime Yes. That's the correct one.

I see the package has a structure of com\adobe\business\core\models\TextModel.java

whereas in the log it shows com.adobe.oursite.core.models.TextModel.

Is this something you modifed while posting the question or this is how it is added on the HTL file for the component?

If this is how it is added on the component HTL, then you will need to replace oursite with business in the HTL and it will start working.

 

Also please post both HTL and Model class code here so that I can confirm.

 

Thanks!

Avatar

Level 5
@Asutosh_Jena_ - Yes, that is something I modified when posting the question. The path is com.adobe.business.core.models.TextModel. Would I find the HTL and Model class code in the TextModel.java file? I took a look and didn't see it.

Avatar

Community Advisor

Hi @Codelime 

 

com.adobe.business.core.models.TextModel - This is the model class. So please post the code for this file.

 

Also for the HTL, you will find it within your component which will be located under apps folder.

Based on your component name you will be able to find it within the project specific folder in apps.

 

Thanks!

Avatar

Level 5

 

 

      0 TIMER_START{Request Processing}

      0 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>

      4 LOG Method=GET, PathInfo=null

      5 TIMER_START{handleSecurity}

    985 TIMER_END{979,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@3e0cbfba returns true

   1205 TIMER_START{ResourceResolution}

   1303 TIMER_END{97,ResourceResolution} URI=/content/business/en/externalsite/internet/jcr:content/root/text_485462042.html resolves to Resource=JcrNodeResource, type=business/insights/components/overlays/text, superType=null, path=/content/business/en/externalsite/internet/jcr:content/root/text_485462042

   1308 LOG Resource Path Info: SlingRequestPathInfo: path='/content/business/en/externalsite/internet/jcr:content/root/text_485462042', selectorString='null', extension='html', suffix='null'

   1308 TIMER_START{ServletResolution}

   1312 TIMER_START{resolveServlet(/content/business/en/externalsite/internet/jcr:content/root/text_485462042)}

   1323 TIMER_END{7,resolveServlet(/content/business/en/externalsite/internet/jcr:content/root/text_485462042)} Using servlet /apps/business/insights/components/overlays/text/text.html

   1325 TIMER_END{16,ServletResolution} URI=/content/business/en/externalsite/internet/jcr:content/root/text_485462042.html handled by Servlet=/apps/business/insights/components/overlays/text/text.html

   1327 LOG Applying Requestfilters

   1330 LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl

   1335 LOG Calling filter: org.apache.sling.security.impl.ContentDispositionFilter

   1338 LOG Calling filter: com.adobe.granite.csrf.impl.CSRFFilter

   1342 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter

   1345 LOG Calling filter: com.adobe.granite.httpcache.impl.InnerCacheFilter

   1348 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter

   1351 LOG Calling filter: com.adobe.cq.mcm.campaign.servlets.CampaignCopyTracker

   1354 LOG Calling filter: com.adobe.cq.history.impl.HistoryRequestFilter

   1577 LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter

   1584 LOG Calling filter: com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet

   1587 LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter

   1590 LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet

   1592 LOG Calling filter: com.adobe.cq.social.commons.cors.CORSAuthenticationFilter

   1595 LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter

   1602 LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter

   1604 LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl

   1729 LOG Calling filter: com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter

   1732 LOG Calling filter: com.adobe.granite.requests.logging.impl.RequestLoggerImpl

   1736 LOG Calling filter: com.adobe.granite.rest.impl.servlet.ApiResourceFilter

   1787 LOG Calling filter: com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler

   1790 LOG Calling filter: com.day.cq.dam.core.impl.servlet.ActivityRecordHandler

   1799 LOG Calling filter: com.adobe.cq.social.ugcbase.security.impl.SaferSlingPostServlet

   1801 LOG Calling filter: com.day.cq.wcm.core.impl.warp.TimeWarpFilter

   1809 LOG Applying Componentfilters

   1811 LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter

   1814 LOG Calling filter: com.day.cq.wcm.core.impl.page.PageLockFilter

   1817 LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter

   2953 LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html], order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobile: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=mobiledebug, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobiledebug: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=contentsync, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-contentsync: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), serializer=Config(type=htmlwriter, config={}))}

   2994 LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter

   3005 TIMER_START{/apps/business/insights/components/overlays/text/text.html#0}

   4990 LOG SCRIPT ERROR: Identifier com.adobe.business.core.models.TextModel cannot be correctly instantiated by the Use API

   5008 TIMER_END{2002,/apps/business/insights/components/overlays/text/text.html#0}

  21801 TIMER_END{21800,Request Processing} Dumping SlingRequestProgressTracker Entries

 

 

 

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Identifier com.adobe.business.core.models.TextModel cannot be correctly instantiated by the Use API

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

                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:82)

                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:72)

                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:72)

                at com.day.cq.wcm.core.impl.page.PageLockFilter.doFilter(PageLockFilter.java:91)

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

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

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

                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:76)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                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:72)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                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:72)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                at org.apache.sling.engine.impl.parameters.RequestParameterSupportConfigurer.doFilter(RequestParameterSupportConfigurer.java:63)

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

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

                at org.apache.felix.http.base.internal.dispatch.Dispatcher$1.doFilter(Dispatcher.java:146)

                at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1002)

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

                at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:136)

                at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1008)

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

                at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:136)

                at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1008)

                at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.invokePreprocessors(WhiteboardManager.java:1012)

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

                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:852)

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

                at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

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

                at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

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

                at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)

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

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

                at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)

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

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

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

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

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

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

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

                at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)

                at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

                at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)

                at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)

                at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)

                at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)

                at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)

                at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367)

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

                at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918)

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

Caused by: org.apache.sling.scripting.sightly.SightlyException: Identifier com.adobe.business.core.models.TextModel 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:77)

                at org.apache.sling.scripting.sightly.apps.business.insights.components.overlays.text.text_html.render(text_html.java:53)

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

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

                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)

                ... 131 more

Caused by: org.apache.sling.models.factory.MissingElementsException: Could not inject all required fields into class com.adobe.business.core.models.TextModel

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

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

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

                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)

                ... 138 more

                Suppressed: org.apache.sling.models.factory.MissingElementException: Could not inject private com.day.cq.wcm.api.Page com.adobe.business.core.models.AbstractComponentModel.page

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

                                ... 142 more

                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:635)

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

                                ... 142 more

Avatar

Community Advisor
Could you please post the model class code here?

Avatar

Level 5

Can you point me in the right direction for finding the model class code?

Avatar

Community Advisor

@Codelime Your model class must be present under com.adobe.business.core.models package with class name as TextModel in your code module where all the java classes are present.

 

Thanks!

Avatar

Level 5

Is this what I'm looking for? I went to CRXDE and searched for "TextModel" and found six references, including this one:

 

<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2015 Adobe
~
~ 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<div data-sly-use.textModel="com.adobe.cq.wcm.core.components.models.Text"
data-sly-use.templates="core/wcm/components/commons/v1/templates.html"
data-sly-test.text="${textModel.text}"
class="cmp-text">
<p class="cmp-text__paragraph"
data-sly-unwrap="${textModel.isRichText}">${text @ context = textModel.isRichText ? 'html' : 'text'}</p>
</div>
<sly data-sly-call="${templates.placeholder @ isEmpty = !text, classAppend='cmp-text'}"></sly>

Avatar

Community Advisor

Hi @Codelime 

You will not find the model class in CRX/DE. You will have a maven project/code base for your project. All the Java classes will be available within the core module of the maven project.

Do you see that package available in your code? Please see the sample screenshot of the maven prject for wknd:

 

asutosh_j3_0-1617766508757.png

 

Avatar

Community Advisor

@Codelime 

Caused by: org.apache.sling.models.factory.MissingElementsException: Could not inject all required fields into class com.adobe.business.core.models.TextModel

Field or few Fields in Sling Model is/are not being injected.

Try setting defaultInjectionStrategy as optional at class level or mark field as optional.

@Model(adaptables=Resource.class, defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL)
@Inject @Optional
private String anyField;

If still not working, share your Sling Model code.

Avatar

Level 5
Hi @Anudeep_Garnepudi. Which file do I access to make this update? I searched my Core folder and found JCRHelper.java, but wasn't sure if that's the correct file.

Avatar

Level 5

Here's my TextModel.java file:

 

package com.adobe.business.core.models;

import javax.annotation.PostConstruct;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import com.adobe.business.core.utils.Markdown;
import com.adobe.cq.export.json.ExporterConstants;

@Model(adaptables={SlingHttpServletRequest.classResource.class},
       adapters={TextModel.class},
       resourceType={"business/insights/components/overlays/text"})

public class TextModel extends AbstractComponentModel {
    
    @ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL, name="backgroundColor")
    private String backgroundColor;
    
    @ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL, name="textColor")
    private String textColor;
    
    @ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL, name="text")
    private String text;
    
    @ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL, name="fullWidth")
    private boolean fullWidth;
    
    public String getBackgroundColor() {
        return backgroundColor;
    }

    public String getTextColor() {
        return textColor;
    }
    
    public boolean getFullWidth() { return fullWidth; }

    public String getText() {
        String out = text;
        if(out.contains(".jpg"))
        {
            out.replaceAll(".jpg"".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
        }
        else if(out.contains(".jpeg"))
        {
            out.replaceAll(".jpeg"".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
        }
        else if(out.contains(".png"))
        {
            out.replaceAll(".png"".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
        }
        return Markdown.parse(text);
    }

    @PostConstruct
    private void initModel()
    {
        Markdown.setResourceResolver(this.getResource().getResourceResolver());
    }
}

Avatar

Community Advisor

Hi @Codelime 

 

Can you try with the below change:

 

package com.adobe.business.core.models;

import javax.annotation.PostConstruct;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import com.adobe.business.core.utils.Markdown;
import com.adobe.cq.export.json.ExporterConstants;

@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}, adapters = {TextModel.class},
resourceType = {"business/insights/components/overlays/text"},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class TextModel extends AbstractComponentModel {

@ValueMapValue(name = "backgroundColor")
private String backgroundColor;

@ValueMapValue(name = "textColor")
private String textColor;

@ValueMapValue(name = "text")
private String text;

@ValueMapValue(name = "fullWidth")
private boolean fullWidth;

public String getBackgroundColor() {
return backgroundColor;
}

public String getTextColor() {
return textColor;
}

public boolean getFullWidth() {
return fullWidth;
}

public String getText() {
String out = text;
if (out.contains(".jpg")) {
out.replaceAll(".jpg", ".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
} else if (out.contains(".jpeg")) {
out.replaceAll(".jpeg", ".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
} else if (out.contains(".png")) {
out.replaceAll(".png", ".jpeg/_jcr_content/renditions/cq5dam.web.816.480.jpeg");
}
return Markdown.parse(text);
}

@PostConstruct
private void initModel() {
Markdown.setResourceResolver(this.getResource().getResourceResolver());
}
}

Avatar

Level 5

@Asutosh_Jena_ - I updated the TextModel.java class with your code and then tried to add a Text Editor component to a page in my localhost, but got the same error. After updating the code, do I need to do anything first, such as deploy using Maven?

Avatar

Community Advisor
Yes. You will need to build and deploy the code to local instance using maven to see the reflected changes.

Avatar

Level 5
I updated the TextModel.java file and deployed the code to local instance using Maven, tried to add the Text Editor component again, but got the same error.