Hi Liam, AFAIK, the mentioned pattern is not designed to work with Sling Models. It simply uses the adaptTo pattern to transform the adaptable to the given class.
Best, Vlad On Tue, Jun 11, 2019 at 9:00 PM Liam C <[email protected]> wrote: > Hello, > > Is anyone able to replicate this, or to confirm that they have been > able to get something similar to { 'com.example.ModelClass' @ > adaptable=item} working in their projects, please? > > Failing this, is there some workaround that could be used within > Sightly/HTL to adapt a specified resource to a Model class? Although > it is possible to access resource properties (e.g. item.myProperty), > some business logic is contained within models that requires access > via getters rather than via the resource properties. > > Thanks for any guidance. > > Liam > > On 2019/04/01 12:13:43, Liam C <[email protected]> wrote: > > Hello everyone, > > > > In SLING-6504 (https://issues.apache.org/jira/browse/SLING-6504), > > functionality was added to allow adapting a resource that is different > > to the underlying page resource. Feike Visser's example > > ( > https://github.com/heervisscher/htl-examples/commit/93666b5eebdeb36c25adf2e310f55049ec3767ce > ) > > suggests that it is possible and simple, but I haven't managed to > > succesfully implement it. In my experience so far, the adaptable is > > ignored. > > > > If I use the following code in my Sling Model: > > > > @Self > > Resource adaptable; > > public Resource getAdaptableSelf() > > { > > return adaptable; > > } > > > > ...it reveals that the adaptable that reaches the model is null. > > > > I wondered if this might have to do with the fact that the code in > > SLING-6504 modified the JavaUseProvider, but the > > SlingModelsUseProvider handles the instantiation before the > > JavaUseProvider can be reached. > > > > Can anyone confirm whether this option is still working in Sling 11? > > > > Thanks, > > > > Liam > > >
