Skip to main content
Level 4
Jun 16, 2016 8:13 AM UTC
Solved

Sling model all fields null

I had my sling models working fine in 6.1 but I am having trouble in 6.2 even a basic example does not work. The model itself is setup and is not null but all the fields with inject on them are null but the model itself is initialised and not null.

Model is:

package com.test.ecomm.aem.testing.core.models.components.content; import javax.inject.Inject; import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Model; @Model(adaptables = Resource.class) public class TestModel { @Inject private String test; public String getTest() { return test; } public void setTest(String test) { this.test = test; } }

And the call to initialise the model is:

Resource resource = resourceResolver.getResource("/content/testSite/en/test5/jcr:content/par/testing"); TestModel test = resource.adaptTo(TestModel.class); System.out.println("tom model is " + test.getTest());
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Sutty100Accepted solution
Level 4
Jun 16, 2016 10:18 AM UTC

After much hair pulling it looks like a depedency I had added for 6.1 was stepping on the toes of one added for 6.2:

<dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-atinject_1.0_spec</artifactId> <version>1.0</version> <scope>provided</scope> </dependency>

I removed javax.inject and its working correctly.

3 replies

Sutty100AuthorAccepted solution
Level 4
Jun 16, 2016 10:18 AM UTC

After much hair pulling it looks like a depedency I had added for 6.1 was stepping on the toes of one added for 6.2:

<dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-atinject_1.0_spec</artifactId> <version>1.0</version> <scope>provided</scope> </dependency>

I removed javax.inject and its working correctly.

Translate
smacdonald2008
Level 10
Jun 16, 2016 1:00 PM UTC

We just released AEM 6.2 Sling Model article - https://helpx.adobe.com/experience-manager/using/slingmodel_62.html

This works in AEM 6.2

Translate
kautuk_sahni
Level 9
Jun 16, 2016 1:03 PM UTC

smacdonald2008 wrote...

We just released AEM 6.2 Sling Model article - https://helpx.adobe.com/experience-manager/using/slingmodel_62.html

This works in AEM 6.2

 

Great article Scott.

Translate
Kautuk Sahni