slice with sightly

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

slice with sightly

sandeep rawat
Hi, I am trying to implement slice with sighlty for aem 6.1 project, I am following the https://cognifide.atlassian.net/wiki/display/SLICE/Setting+up+-+4.2 for setting up the slice. Also https://cognifide.atlassian.net/wiki/display/SLICE/Upgrade+procedure+-+4.2 for aem 6.1.

After doing this I have created a model as below

package com.myproj.sample.module;
import com.cognifide.slice.mapper.annotation.JcrProperty;
import com.cognifide.slice.mapper.annotation.SliceResource;
import com.day.cq.wcm.api.PageManager;
import com.google.inject.Inject;

@SliceResource
class ArticleModel {
    @JcrProperty
    private String title;
    @JcrProperty
    private String subtitle;
    private final PageManager pageManager;
    @Inject
    public ArticleModel(PageManager pageManager) {this.pageManager = pageManager;}
    public String getTitle() {return title;}
    public String getSubtitle() {return subtitle;}
    }
And sightly component html as below
<div data-sly-use.model="com.myproj.sample.module.ArticleModel">
    <div class="title" data-sly-test="${!model.title}" data-sly-unwrap>
        <div data-sly-test="${wcmmode.edit}" data-sly-attribute.class="cq-text-placeholder-ipe">${component.title} placeholder</div>
        ${model.title}
    </div>
    <div class="title">
        ${model.defaultValue}
    </div>
    <div class="subtitle">
        ${model.subtitle}
    </div>
</div>

Now this doesn't print anything but loads of errors as below
Identifier com.myproj.sample.module.ArticleModel cannot be correctly instantiated by the Use API
org.apache.sling.scripting.sightly.SightlyException: Identifier com.myproj.sample.module.ArticleModel cannot be correctly instantiated by the Use API
        at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:91)
        at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:89)

as well as below error

Caused by: org.apache.sling.scripting.sightly.SightlyException: Cannot find class com.myproj.sample.module.ArticleModel.
        at org.apache.sling.scripting.sightly.impl.compiler.SightlyJavaCompilerService.getInstance(SightlyJavaCompilerService.java:126)
        at org.apache.sling.scripting.sightly.impl.engine.extension.use.JavaUseProvider.getPOJOFromRepository(JavaUseProvider.java:125)
        at org.apache.sling.scripting.sightly.impl.engine.extension.use.JavaUseProvider.provide(JavaUseProvider.java:112)
        at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:87)

I have followed the instructions correctly and the project is getting deployed properly in osgi and  activator looks good as well in osgi.

Please suggest what could be the issue, if need I can share my sample project for investigation.

Please suggest the best important points to know before starting slice with aem.

Your suggestions are most appreciated for further implementation of this framework.





Reply | Threaded
Open this post in threaded view
|

Re: slice with sightly

maciej.majchrzak
Administrator
Hi. My first guess would be that your class is either not exported in OSGi or bundle providing this class is not installed correctly. If everything has started properly then you should be able to see an adapter for you class at http://localhost:4502/system/console/status-adapters. Can you please verify if your class is available in OSGi? If no, then can you please verify your Activator? (if scanned packages and bundle names match provided filters)
Reply | Threaded
Open this post in threaded view
|

Re: slice with sightly

sandeep rawat
This post was updated on .
Hi Maciej, Greetings, thanks for the resolution, the issue was due to @OsgiService, this was not included in the model, after adding this as ArticleModel(@OsgiService .... fixed the issues.

@Inject
        public HelloWorldModel(@OsgiService SlingSettingsService settings,
                        BusinessLogicProvider logicProvider) {
                this.settings = settings;
                this.logicProvider = logicProvider;
        }

Thanks for the support, really appreciated.