[ 
https://issues.apache.org/jira/browse/SLING-3342?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13884036#comment-13884036
 ] 

Felix Meschberger commented on SLING-3342:
------------------------------------------

The class JavaDoc of SlingBindings states:

{code:java}
/**
 * The <code>SlingBindings</code> class is used to prepare global variables
 * for script execution. The constants in this class define names of variables
 * which <em>MUST</em> or <em>MAY</em> be provided for the script execution.
 * Other variables may be define as callers see fit.
 */
public class SlingBindings extends HashMap<String, Object> {
{code}

I think mostly clear.

> Do not use SlingBindings in Java code
> -------------------------------------
>
>                 Key: SLING-3342
>                 URL: https://issues.apache.org/jira/browse/SLING-3342
>             Project: Sling
>          Issue Type: Task
>          Components: Best practices
>            Reporter: Bertrand Delacretaz
>            Assignee: Bertrand Delacretaz
>            Priority: Minor
>
> **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);



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to