Level 1
Level 2
Melden Sie sich an, um alle Badges zu sehen
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.
Gelöst! Gehe zu Lösung.
Zugriffe
Antworten
Likes gesamt
Check Feike code example here -- htl-examples/TitleImpl.java at master · heervisscher/htl-examples · GitHub
Zugriffe
Antworten
Likes gesamt
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;
Zugriffe
Antworten
Likes gesamt
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.
Zugriffe
Antworten
Likes gesamt
Check Feike code example here -- htl-examples/TitleImpl.java at master · heervisscher/htl-examples · GitHub
Zugriffe
Antworten
Likes gesamt
The snippet shared by Feike doesn't help me with the use-case I have.
Zugriffe
Antworten
Likes gesamt
Feike Visser - can you look here when you can - thxs
Zugriffe
Antworten
Likes gesamt
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?
Zugriffe
Antworten
Likes gesamt
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.]
Zugriffe
Antworten
Likes gesamt
Hey was this resolved , as i am facing the same issue
Zugriffe
Antworten
Likes gesamt
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten