[
https://issues.apache.org/jira/browse/SLING-5739?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15293565#comment-15293565
]
Georg Henzler commented on SLING-5739:
--------------------------------------
{quote}
this is actually about injecting a property of the child resource, not the
child resource itself.
{quote}
This is already possible with
{code}
@Inject @Named("path/to/resource/jcr:title") @Source("valuemap") // or
@ValueMapValue
private String titleFromSubResource;
{code}
{quote}
In terms of other `@Via` providers, one more that could make sense is a path
reference provider.
{quote}
Generally, I think it will almost always be better to create its own model for
those use cases (flattening into one Pojo on java side what is structured in
the JCR will not make the code better readable or maintainable). However if
really needed, this we can already almost achieve today:
{code}
@Inject @Named("otherPath") @Source("resource-path") // or
@ResourePath(name="otherPath")
private Resource propertyFromSomeOtherResource; // we can get that resource
today, but not yet only the property "otherProperty"
{code}
But for this I would probably fairly easy to just extend @ResourcePath a bit to
make the following work:
{code}
@Inject @Named("otherPath") @TargetProperty("otherProperty")
@Source("resource-path") // or @ResourePath(name="otherPath",
targetProperty="otherProperty")
private String propertyFromSomeOtherResource;
{code}
It would fairly easy to extend @ResourcePath to lookup the resource's ValueMap
and use the target property name to lookup the value to inject.
Certainly, this would be more light-weight than introducing another fairly
complicated ViaProvider SPI.
> [Sling Models] Allow for extensible @Via providers
> --------------------------------------------------
>
> Key: SLING-5739
> URL: https://issues.apache.org/jira/browse/SLING-5739
> Project: Sling
> Issue Type: New Feature
> Components: Extensions
> Reporter: Justin Edelson
>
> Currently, @Via support in Sling Models is limited to JavaBean properties. It
> would be useful to be able to extend this and allow for downstream projects
> to add new @Via providers.
> Proposing to support this by extending the @Via annotation
> {code}
> @Via(value = "jcr:content", type = ChildResource.class)
> {code}
> The default type is BeanProperty (the current behavior).
> New providers can be added by implementing a ViaProvider SPI and provide a
> marker class for use in the annotation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)