I have a class MyList
@Model(adaptables = SlingHttpServletRequest.class,
adapters = MyList.class,
resourceType = MyListImpl.RESOURCE_TYPE)
in Sightly, you can do this
<sling:adaptTo adaptable="${slingRequest}" adaptTo="MyList" var="m"/>
How can I do the same in Java code?
Thanks.
Solved! Go to Solution.
Views
Replies
Total Likes
MyList ml = request.adaptTo(MyList.class);
Views
Replies
Total Likes
MyList ml = request.adaptTo(MyList.class);
Views
Replies
Total Likes
Thanks.
I would like to add more detail and hopefully I can get an answer for that.
I have a path pointing to a node which has the sling:resourceType is myList component. I wrote MyList.java
using @Model(adaptables = SlingHttpServletRequest.class, adapters = MyList.class,resourceType = MyListImpl.RESOURCE_TYPE).
Is there a way I can adaptTo(MyList.class) and get myList object.
If MyList.java implements using @Model(adaptables=Resource), then I can do this
Resource myListResource = resourceResolver.getResource(path);
MyList ml = MyListResource.adaptTo(MyList.class);
Just don't know how to get MyList object when implemented using adaptable is SlingHttpServletRequest.class in Java?
Thanks.
Views
Replies
Total Likes