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

SOLVED

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

ashwinikhaple
Level 2
Level 2

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;

     }

   

    

}

1 Accepted Solution
asutosh_jena
Correct answer by
Community Advisor
Community Advisor

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!

View solution in original post

2 Replies
asutosh_jena
Correct answer by
Community Advisor
Community Advisor

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!

View solution in original post