[
https://issues.apache.org/jira/browse/SLING-3949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14152718#comment-14152718
]
Jason E Bailey commented on SLING-3949:
---------------------------------------
[[email protected]] Custom injector annotations replace the default
annotations and specifically indicate which optional elements are supported.
Currently if you look at the chart in the documentation, via is called out as
an optional element for ValueMapValue, ChildResource, and RequestAttribute.
[~kwin] @ChildResource is using the getChild method of the resource, if the
adaptable is a resouce. I'm referring to using the via attribute to access a
method oon the object.
I think, in retrospect, my example may have been poor because there is a way to
replicate it with the existing set of injectors(resource-resolver). We have a
number of rich models that don't constrain themselves to just resource and
servletrequest and to extract information from these objects we've been using a
custom BeanValue injector. Which is where I was going with the modification of
the @Self annotation. I thought it would be a little less intrusive then adding
another injector.
So let me provide another mock example:
{code}
@Model(adaptables = Page.class)
public class Foo {
@Self(via = "path")
String path; //Page.getPath()
@Self(via="pageTitle")
String title;
@Self(via="parent')
Brand current;
/*.... useful logic */
}
{code}
> Sling Models: Add via support to Self annotation
> ------------------------------------------------
>
> Key: SLING-3949
> URL: https://issues.apache.org/jira/browse/SLING-3949
> Project: Sling
> Issue Type: Improvement
> Reporter: Jason E Bailey
> Priority: Minor
> Labels: models
>
> Allows the object that is to be applied or adapted to come from a property of
> the given adaptable.
> example:
> {code}
> @Model(adaptables = SlingHttpServletRequest.class)
> public class Foo {
> @Self(via = "resourceResolver")
> TagManager tagManager;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)