We have a React component that returns data from the DAM based on the category Tag assigned to it. Is there a way to pass an attribute from React to the sling model and update the model.json with category data to display in React? Or will we have to keep using servlets to achieve this?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @gregy68980908, did you consider to pass the value using GET parameter. Sling model has access to request, so you should be able to retrieve GET param value and update data exposed by model respectively, e.g assuming this is url you are using now
/content/we-retail/language-masters/en.model.json
it can be changed to something like that (this is request you will sent from React)
/content/we-retail/language-masters/en.model.json?attribute=value
In your sling model you can access value like this:
@Self private SlingHttpServletRequest request; private String attributeValue; @PostConstruct protected void init() { this.attributeValue = request.getParameter("attribute"); }
Hi @gregy68980908, did you consider to pass the value using GET parameter. Sling model has access to request, so you should be able to retrieve GET param value and update data exposed by model respectively, e.g assuming this is url you are using now
/content/we-retail/language-masters/en.model.json
it can be changed to something like that (this is request you will sent from React)
/content/we-retail/language-masters/en.model.json?attribute=value
In your sling model you can access value like this:
@Self private SlingHttpServletRequest request; private String attributeValue; @PostConstruct protected void init() { this.attributeValue = request.getParameter("attribute"); }
Views
Likes
Replies