Need to create sling model

Avatar

Avatar

manikanthar1295

Avatar

manikanthar1295

manikanthar1295

02-01-2019

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

Replies

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

840
Arun_Patidar
MVP

02-01-2019

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

Avatar

Avatar

manikanthar1295

Avatar

manikanthar1295

manikanthar1295

02-01-2019

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

Avatar

Ratna_Kumar

MVP

Avatar

Ratna_Kumar

MVP

Ratna_Kumar
MVP

03-01-2019

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

Avatar

Ratna_Kumar

MVP

Avatar

Ratna_Kumar

MVP

Ratna_Kumar
MVP

03-01-2019

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

Avatar

Ratna_Kumar

MVP

Avatar

Ratna_Kumar

MVP

Ratna_Kumar
MVP

03-01-2019

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

Avatar

Avatar

rampai

Avatar

rampai

rampai

03-01-2019

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

Avatar

manikanthar1295

Avatar

manikanthar1295

manikanthar1295

03-01-2019

Hi Ratna kumar,

Thanks for your response here.

I was created the normal folder called testsling

Regards

Manikantha R