Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Need to create sling model

manikanthar1295
Level 4
Level 4

Hi,

I have tried to create sling model in AEM 6.4 i have followed Adobe Experience Manager Help | Creating Adobe Experience Manager 6.3 Sling Model Components

i have gone to http://localhost:4502/crx/de/index.jsp#/content/testsling

i have create folder under content called testsling but after that which type of node i  need to create i'm not getting

bellow are the screen shot

1658570_pastedImage_3.png

I will be help full if any one explain how i  which node i need to select while creating the sling model.

Regards

Manikantha R

7 Replies
Arun_Patidar
Community Advisor
Community Advisor

Hi,

In above tutorial test node is created to store only data, that is not related to sling model. you can create test sling folder and then nt:unstructured node as mentioned in screenshots in the helpx document.

You can read more about sling model at Apache Sling :: Sling Models

manikanthar1295
Level 4
Level 4

Hi Arun,

Thanks for your quick response.

According to you we are not using below sling model  right in tutorial.

package SlingModel63.core;

import javax.inject.Inject;

import org.apache.sling.api.resource.Resource;

import org.apache.sling.models.annotations.Model;

 

@Model(adaptables = Resource.class)

public class UserInfo {

    @Inject

    private String firstName;

    @Inject

    private String lastName;

    @Inject

    private String technology;

     

    public String getFirstName() {

        return firstName;

    }

    public String getLastName() {

        return lastName;

    }

    public String getTechnology() {

        return technology;

    }

 

}

Correct me if i'm wrong.

Regards

Manikantha R

Ratna_Kumar
Community Advisor
Community Advisor

Hi Manikanta,

We are using sling models in that article and please make note the purpose of Sling models is to define the model object i.e., java object and map that object to Sling resources.

package SlingModel63.core;

import javax.inject.Inject;

import org.apache.sling.api.resource.Resource;

import org.apache.sling.models.annotations.Model;

@Model(adaptables = Resource.class)

public class UserInfo {

    @Inject

    private String firstName;

    @Inject

    private String lastName;

    @Inject

    private String technology;

    

    public String getFirstName() {

        return firstName;

    }

    public String getLastName() {

        return lastName;

    }

    public String getTechnology() {

        return technology;

    }

}

In above code you are defining the java objects and map that into sling resources of that slingmodel node as in the screenshot.

Its just a node you can create and get that node using resource object and map that objects to sling resources.

Resource resource = resolver.getResource("/content/testsling/slingmodel");

Hence node called testsling/slingmodel is only dummy node we created to store the data for our reference and its not related to Sling models.

Hope this helps!!

Thanks,

Ratna Kumar.

Ratna_Kumar
Community Advisor
Community Advisor

Best way to install the package in the start of the article and test it. The testsling node is of type sling:Folder and slingmodel node is of type nt:unstructured. Below is the screenshot.

1659246_pastedImage_1.png

Hope this helps!!

Thanks,

Ratna Kumar.

Ratna_Kumar
Community Advisor
Community Advisor

Also, remember please don't create the folder. Create node -> testsling with type sling:Folder!!!

rampai
Level 5
Level 5

Yes Ratna Kumar​ is right, nt:unstructured nodes cannot go under nt:folder node. If you try to do this you will get a 409 conflict error. Nodes of type nt:unstructured can only be created under a node of type sling:Folder if you want a folder per se.

manikanthar1295
Level 4
Level 4

Hi Ratna kumar,

Thanks for your response here.

I was created the normal folder called testsling

Regards

Manikantha R