This may be related to https://issues.apache.org/jira/browse/SLING-4155 
<https://issues.apache.org/jira/browse/SLING-4155>.
Please have a look.
Konrad

> On 14 Apr 2016, at 10:27, Oliver Lietz <[email protected]> wrote:
> 
> On Thursday 14 April 2016 07:47:33 Stefan Seifert wrote:
>> please try to use use @Inject or even better @SlingObject on the "request"
>> variable instead of @Self - then is should work.
>> 
>> for the "resource" parameter i would prefer @SlingObject as well instead of
>> @Inject to make it more explicit and a litte bit more efficient (no need it
>> iterate over all potential injectors internally to find the right match).
> 
> That way it works:
> 
> @Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
> public class MyModel {
> 
>    @SlingObject
>    private Resource resource;
> 
>    @SlingObject(optional = true)
>    private SlingHttpServletRequest request;
> 
> }
> 
> Using @Optional instead of optional = true breaks injection. So there is a 
> problem with @Optional. Can you have a look? Should I file an issue?
> 
> Thanks, Stefan!
> 
> O.
> 
>> stefan
>> 
>>> -----Original Message-----
>>> From: Oliver Lietz [mailto:[email protected]]
>>> Sent: Thursday, April 14, 2016 9:42 AM
>>> To: [email protected]
>>> Subject: [Models] Injecting from two sources
>>> 
>>> Hi,
>>> 
>>> is it somehow possible to inject both a resource and a request where the
>>> request is optional and should not break injection when not available?
>>> 
>>> @Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
>>> public class MyModel {
>>> 
>>>   @Inject
>>>   private Resource resource;
>>> 
>>>   @Self
>>>   @Optional
>>>   private SlingHttpServletRequest request;
>>> 
>>> }
>>> 
>>> In my case injection fails with SlingHttpServletRequest not adaptable from
>>> JcrNodeResource.
>>> 
>>> Thanks,
>>> O.
> 

Reply via email to