Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
At present, it is somewhat complex to generate Sling Model objects (or really, any adapter class) from an included resource. This is especially true when the adaptable is the SlingHttpServletRequest object.
There are a few different cases which are problematic:
1. When you want to inject an object adapted from a child resource where the adaptable is a request object (i.e. you want to override the request.getResource() to the child resource)
2. When you want to inject an object adapted from a child resource (regardless of the adaptable) and the model class depends upon the Script Bindings.
In the first case, this currently requires creating a wrapper request. The second case is more complex to solve as (to do it correctly) requires re-invoking all of the BindingsValuesProviders (which entails creating a fake ScriptEngine).
To solve both issues, I would like to add a new method named getModelFromWrappedRequest. Parameters would be SlingHttpServletRequest, Resource, Class.
This method would create a wrapped request with the passed resource, set the bindings to a new object and reinvoke the BVPs.
Patch to follow, but I wanted to file this early to get any feedback.
Attachments
Attachments
Issue Links
- is related to
-
SLING-11732 Add method ModelFactory.createModelFromWrappedRequest(...)
- Closed