Sling model all fields null | Community
Skip to main content
Level 4
June 16, 2016
Solved

Sling model all fields null

  • June 16, 2016
  • 3 replies
  • 2429 views

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.
Best answer by Sutty100

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
June 16, 2016

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.

smacdonald2008
Level 10
June 16, 2016

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

kautuk_sahni
Community Manager
Community Manager
June 16, 2016

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.

Kautuk Sahni