Expand my Community achievements bar.

Need to create sling model

Avatar

Level 6

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

Avatar

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



Arun Patidar

Avatar

Level 6

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

Avatar

Level 10

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.

Avatar

Level 10

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.

Avatar

Level 10

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

Avatar

Level 6

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.

Avatar

Level 6

Hi Ratna kumar,

Thanks for your response here.

I was created the normal folder called testsling

Regards

Manikantha R