Highlighted

Sling model : @PostConstruct is not called and null values are thrown.

Avatar

Avatar

dibyajyotis2501

Avatar

dibyajyotis2501

dibyajyotis2501

23-11-2019

I'm trying to bind a sling model with my sightly via use api. But facing couple of issues.

1)  The specific sling model seems not getting registered successfully while checking adapter status. (but bundle is active and running)

2)  Flow is not getting inside @PostConstruct method.

3)   Although dialog values with exact property name are present in JCR, when the page is viewed, its showing null.

Steps followed to rectify:

1) in the models core pom file, added below build plugin with <Sling-Model-Packages>

<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <extensions>true</extensions>
  <configuration>
       <instructions>
             <Import-Package>javax.inject;version=0.0.0,*</Import-Package>
                 <Sling-Model-Packages>
                  com.XX.YY.models

                 </Sling-Model-Packages>
            <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
       </instructions>
  </configuration>
</plugin>

2) Added the below dependency at core pom.

<dependency>
  <groupId>javax.inject</groupId>
  <artifactId>javax.inject</artifactId>
</dependency>

3) added simlar dependency at parent pom under <dependencyManagement />.  Also the artifact 'geronimo-atinject_1.0_spec' is already existing in parent POM.

<dependency>
  <groupId>javax.inject</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1</version>
  <scope>provided</scope>
</dependency>

4) the page where the component has been used, (in which sling model is tied), is correctly reflecting authored values at JCR  /content/..  level.

1857819_pastedImage_6.png

5) 1857820_pastedImage_9.png

         sightly markup with dialog nodes.

6)  Model class as below.

1858185_pastedImage_0.png

Can anyone suggest how to solve this issue??