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
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Boost 1
Level 1
ashwinikhaple
Level 1

Like

1 like

Total Posts

16 posts

Correct Reply

1 solution
Top badges earned
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 1
Level 1
ashwinikhaple
Level 1

Like

1 like

Total Posts

16 posts

Correct Reply

1 solution
Top badges earned
Boost 1
Applaud 5
Affirm 1
View profile
ashwinikhaple
Level 1

07-04-2021

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 @Optional

       public String text;

      @RequestAttribute @Optional

        public String username;

        

    @PostConstruct

     protected void init()

     {

         text="hello "+text;

     }

   

    

}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

544 likes

Total Posts

663 posts

Correct Reply

190 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

544 likes

Total Posts

663 posts

Correct Reply

190 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

07-04-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!

Answers (1)

Answers (1)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

610 likes

Total Posts

588 posts

Correct Reply

230 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

610 likes

Total Posts

588 posts

Correct Reply

230 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

07-04-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