Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Sling model all fields null

Avatar

Level 5

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());
1 Accepted Solution

Avatar

Correct answer by
Level 5

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.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 5

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.

Avatar

Administrator

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