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;
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
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!
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!
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
Views
Likes
Replies