Trying to Pass the parameters from sightly to the slingmodel and read the values , manipulate it and display in frontend | Community
Skip to main content
Level 2
April 7, 2021
Solved

Trying to Pass the parameters from sightly to the slingmodel and read the values , manipulate it and display in frontend

  • April 7, 2021
  • 2 replies
  • 1450 views

I want to pass parameters text and username from sightly to sling model and display in frontend. Pls Help

Sightly Code

<sly data-sly-use.mySlingModal="${'com.aem.demo.core.models.MyComponentModel' @ text='Hi!!'}"></sly>

 

MyComponentModel.java

@Model(adaptables = SlingHttpServletRequest.class)

public class MyComponentModel

{

       @RequestAttribute @7392697

       public String text;

      @RequestAttribute @7392697

        public String username;

        

    @PostConstruct

     protected void init()

     {

         text="hello "+text;

     }

   

    

}

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 Asutosh_Jena_

Hi @ashwinikhaple 

Please use the below code:

 

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class SomeModel {

@RequestAttribute
private String text;

@RequestAttribute
private String userName;

@PostConstruct
protected void init() {
//do anything
}

public String getText() {
return text;
}

public String getUserName() {
return userName;
}
}  

 

<sly data-sly-use.model="${'com.something.core.models.SomeModel' @text = properties.text, userName = properties.userName}">
Text -> "${model.text}"
UserName -> "${model.userName}"

</sly>

Hope this helps!

Thanks!

2 replies

Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
April 7, 2021

Hi @ashwinikhaple 

Please use the below code:

 

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class SomeModel {

@RequestAttribute
private String text;

@RequestAttribute
private String userName;

@PostConstruct
protected void init() {
//do anything
}

public String getText() {
return text;
}

public String getUserName() {
return userName;
}
}  

 

<sly data-sly-use.model="${'com.something.core.models.SomeModel' @text = properties.text, userName = properties.userName}">
Text -> "${model.text}"
UserName -> "${model.userName}"

</sly>

Hope this helps!

Thanks!

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
April 7, 2021

@ashwinikhaple,

Take a look at this article, where your answer is highlighted - https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript