Hi,
Currently have a model class with @Model(adaptables = Resource.class). The code written so far works absolutely fine.
To this , I have now added the below
@Model(adaptables = { Resource.class, SlingHttpServletRequest.class })
@Inject
SlingHttpServletRequest request;
as I want to make use of request Object in my code.
Referred multiple links on this, Few examples :
https://www.slideshare.net/AEMHub2014/sling-models-by-justin-edelson-final
http://www.wemblog.com/2014/11/how-to-use-sling-models-in-cq56.html
https://forums.adobe.com/thread/2329143
But still not working. " Identifier xysdkfjk cannot be correctly instantiated by the Use API" is the error I keep getting.
Any thoughts on this will be helpful.
Solved! Go to Solution.
Views
Replies
Total Likes
Check Feike code example here -- htl-examples/TitleImpl.java at master · heervisscher/htl-examples · GitHub
Views
Replies
Total Likes
You can achieve sling request object by different ways :
@Self
private SlingHttpServletRequest slingHttpServletRequest;
By Constructor
@Model(adaptables= SlingHttpServletRequest.class)
public class TestModel {
private final SlingHttpServletRequest request;
public TestModel(SlingHttpServletRequest r){
this.request = r;
}
By Name
private SlingHttpServletRequest request;
Views
Replies
Total Likes
Hi zeeshank15007365,
Thank you for your reply.
To get the request Object to my existing class which is working fine, I did the below :
1] Added request to adaptables which just had resource earlier : @Model(adaptables = { Resource.class, SlingHttpServletRequest.class })
2] Tried with
@Self
private SlingHttpServletRequest slingHttpServletRequest;
and
By Name
private SlingHttpServletRequest request;
but no luck. Not sure what is it that I am missing.
Will try the constructor method too and let you know how it goes. Thanks again for replying on this query of mine.
Views
Replies
Total Likes
Check Feike code example here -- htl-examples/TitleImpl.java at master · heervisscher/htl-examples · GitHub
Views
Replies
Total Likes
The snippet shared by Feike doesn't help me with the use-case I have.
Views
Replies
Total Likes
Feike Visser - can you look here when you can - thxs
Views
Replies
Total Likes
Where you able to succesfuuly compile this code? I have never tried to make use of a Request object in a Sling Model. Only a Sling Servlet. What are you trying to do?
Views
Replies
Total Likes
Hi Scott/Feike,
In component model class, was trying to get request object to use for api resolver.map(). However, now using resolver.map that takes in a single argument rather than the one along with request.
However, it would be helpful if you can let us know how can we take request object in Component model class[in case we need it sometime in the future.]
Views
Replies
Total Likes
Hey was this resolved , as i am facing the same issue
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies