Sling Model and Sightly | Community
Skip to main content
Level 2
October 16, 2015
Solved

Sling Model and Sightly

  • October 16, 2015
  • 4 replies
  • 6151 views

I have a Sling Model class and i want to use it in sightly.

My Sling model should be map to the JCR node in order to access the node properties.

So how to map sightly with Sling Model and JCR node?

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 JustinEd3

Assuming your Sling Model class is adaptable from either Resource or SlingHttpServletRequest, you can specify the fully-qualified class name in the data-sly-use attribute. See http://experiencedelivers.adobe.com/cemblog/en/experiencedelivers/2014/04/sightly-intro-part-4.html

4 replies

JustinEd3Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

Assuming your Sling Model class is adaptable from either Resource or SlingHttpServletRequest, you can specify the fully-qualified class name in the data-sly-use attribute. See http://experiencedelivers.adobe.com/cemblog/en/experiencedelivers/2014/04/sightly-intro-part-4.html

smacdonald2008
Level 10
October 16, 2015

We also have a community article that uses Sighty and Java.

<div data-sly-use.heroTextObject="com.mycompany.myproject.sightly.HeroTextComponent" data-sly-test="${heroTextObject}">
       <h1>${heroTextObject.heroTextBean.headingText}</h1>
       <p>${heroTextObject.heroTextBean.description}</p>    
</div>

See: http://helpx.adobe.com/experience-manager/using/creating-sightly-component.html

ad6Author
Level 2
October 16, 2015

thanks for your reply.

I have a following Sling Model class :

package com;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;

import javax.inject.Inject;
import javax.inject.Named;


@Model(adaptables=Resource.class)
public class Phone {
    @Inject
    @Optional
    public String defaultColour;
    @Inject
    @Optional
    public String modelName;
  
    public String getDefaultColour() {
        return defaultColour;
    }
    public void setDefaultColour(String defaultColour) {
        this.defaultColour = defaultColour;
    }
    public String getModelName() {
        return modelName;
    }
    public void setModelName(String modelName) {
        this.modelName = modelName;
    }
   }

 

THis is the path of resource which i need to adapt in sling model:

/etc/product/phone/apple

Follwoing is the sightly code :

<div data-sly-use.geocode="com.Phone">

<div> <img src ='${phone.defaultColour}' title ="Logo Image" style="float:left;width:196px;"/> </div>
</div>

 

in this ${phone.defaultColour} is coming as empty.

So how to map my sling model class the the resource path using sightly.

Adobe Employee
October 16, 2015

Your use directive has the name 'geocode' and your expression has the name 'phone'. Might that be the problem?