Expand my Community achievements bar.

SOLVED

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

Avatar

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 @Deleted Account

       public String text;

      @RequestAttribute @Deleted Account

        public String username;

        

    @PostConstruct

     protected void init()

     {

         text="hello "+text;

     }

   

    

}

1 Accepted Solution

Avatar

Correct answer by
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

Avatar

Correct answer by
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!