Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-7015

Add Utility Method to ModelFactory to help proper model creation from child resources in a request context

    XMLWordPrintableJSON

Details

    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

        1. SLING-7015.diff
          28 kB
          Justin Edelson

        Issue Links

          Activity

            People

              justinedelson Justin Edelson
              justinedelson Justin Edelson
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: