You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by olimination <ol...@gmail.com> on 2016/04/20 17:19:21 UTC

Sling Models: ResourcePath annotation with relative path support?

Hi,

I'm using Sling Models (cool stuff, thanks for that!) and would like to get
a resource relative to the current rendered resource. Actually I want to
get an InputStream from a nt:file node and so I thought to make this with
the ResourcePath annotation with a relative path.

Something like:

@ResourcePath(path = "mynode/jcr:content")
private InputStream myfile;

but this seems not to be supported or maybe I missed some documentation how
to do it?

Alternatively I can use @Self and the navigate and adapt it to an
InputStream.

But I thought maybe there is a possibility to use the @ResourcePath
annotation with a relative path.


Thanks for help!
Oli

Re: Sling Models: ResourcePath annotation with relative path support?

Posted by olimination <ol...@gmail.com>.
Thanks Stefan for your reply! I tried with @ChildResource and it worked
like a charm - cool!

As far as I understand the @ResourcePath javadoc, you can use this
annotation to inject a resource by given path, but not a relative path.



On Wed, Apr 20, 2016 at 5:38 PM, Stefan Seifert <ss...@pro-vision.de>
wrote:

> @ResourcePath injects the resource path (string), not a resource
> identified by a path.
>
> please try the @ChildResource injector with name = child path.
>
> https://sling.apache.org/documentation/bundles/models.html#available-injectors
>
> stefan
>
> >-----Original Message-----
> >From: olimination [mailto:olimination@gmail.com]
> >Sent: Wednesday, April 20, 2016 5:19 PM
> >To: users@sling.apache.org
> >Subject: Sling Models: ResourcePath annotation with relative path support?
> >
> >Hi,
> >
> >I'm using Sling Models (cool stuff, thanks for that!) and would like to
> get
> >a resource relative to the current rendered resource. Actually I want to
> >get an InputStream from a nt:file node and so I thought to make this with
> >the ResourcePath annotation with a relative path.
> >
> >Something like:
> >
> >@ResourcePath(path = "mynode/jcr:content")
> >private InputStream myfile;
> >
> >but this seems not to be supported or maybe I missed some documentation
> how
> >to do it?
> >
> >Alternatively I can use @Self and the navigate and adapt it to an
> >InputStream.
> >
> >But I thought maybe there is a possibility to use the @ResourcePath
> >annotation with a relative path.
> >
> >
> >Thanks for help!
> >Oli
>



-- 
=======================
(C)olimination.com

RE: Sling Models: ResourcePath annotation with relative path support?

Posted by Stefan Seifert <ss...@pro-vision.de>.
@ResourcePath injects the resource path (string), not a resource identified by a path.

please try the @ChildResource injector with name = child path.
https://sling.apache.org/documentation/bundles/models.html#available-injectors

stefan

>-----Original Message-----
>From: olimination [mailto:olimination@gmail.com]
>Sent: Wednesday, April 20, 2016 5:19 PM
>To: users@sling.apache.org
>Subject: Sling Models: ResourcePath annotation with relative path support?
>
>Hi,
>
>I'm using Sling Models (cool stuff, thanks for that!) and would like to get
>a resource relative to the current rendered resource. Actually I want to
>get an InputStream from a nt:file node and so I thought to make this with
>the ResourcePath annotation with a relative path.
>
>Something like:
>
>@ResourcePath(path = "mynode/jcr:content")
>private InputStream myfile;
>
>but this seems not to be supported or maybe I missed some documentation how
>to do it?
>
>Alternatively I can use @Self and the navigate and adapt it to an
>InputStream.
>
>But I thought maybe there is a possibility to use the @ResourcePath
>annotation with a relative path.
>
>
>Thanks for help!
>Oli