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

Do not use SlingBindings in Java code

    XMLWordPrintableJSON

Details

    • Task
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • None
    • None
    • Best practices
    • None

    Description

      *DRAFT* - to be reviewed, and we need to update the SlingBindings javadocs as well.

      SlingBindings is meant to be used in Sling scripts.

      It might be available as a Request attribute in some cases, as Sling sets that before running scripts, but one cannot rely on that in java code.

      There’s usually no reason to use it in Java code anyway, all the services that it provides are available directly, for example via an @Reference annotation.

      Here’s a typical counter-example which should use an @Reference to the FooBar service instead:

      // Do NOT do that!
      SlingBindings bindings = (SlingBindings)request.getAttribute(SlingBindings.class.getName());
      SlingScriptHelper scriptHelper = bindings.getSling();
      FooBar fb = scriptHelper.getService(FoorBar.class);

      Attachments

        Activity

          People

            Unassigned Unassigned
            bdelacretaz Bertrand Delacretaz
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: