Replies: 3 comments 8 replies
-
Hi, can you give some context of what you're trying to do? AssetModel is rarely adapted from request itself - rather via a model factory fromWrappedRequest. To be honest, I would probably create a pojo wrapper that you just pass the assetModel to. I'm not clear where you'd want to use your wrapping delegate |
Beta Was this translation helpful? Give feedback.
-
@DigiLiviu So AssetModel can be adapted from a request or a resource. I always try to use a request as the adaptable when i can, because it provides some extra context -- some computed properties (for example [1]) can the request to provide more context. This is actually really rare, but when i can i do just cuz more is more :) So, youre fine doing what youre doing - and if your @self is an request, then its great. if you dont have a request, then you can definitely do resource.adaptTo(AssetModel.class). That said, it sounds like, since youre in the context of a servlet, that you do have a request - so you could at the very least use the modelFactory pattern to turn the resources into AssetModels with the current request's context. I am curious as to why you need to make this AJAX call back to a servlet -- why cant you just make a new Sling Model for your details component, that performs this query and then have an HTL that outputs the related assets? An example is of one of these is: You could have a RelatedAssetsImpl.java Sling Model that looks something like:
Or ... you could do something similar in custom computed property like [2] .. and then you can access related assets off any ASC AssetModel via ... Let me know if you want to dig further into either of these approaches, or if there's a good reason to split your component up into a renderer and a servlet that returns the related assets that are AJAX'd in. I can't imagine that looking up related assets would be too slow, since if i recall, the related assets are saved by path - so its very quick to find/get them). |
Beta Was this translation helpful? Give feedback.
-
The more i think about it - the more i like using a Computed Property that does something like the above. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I've been trying to extend the AssetModel using the recommended Delegation pattern and I'm not sure I'm doing it right. Every example is using the ResourceSuperType method but there is no resource type in this case for me to extend from. I'm getting a null object when I try.
I have also tried without it and just using the @DeleGate and @self annotations and that does work in the sense that it generates a AssetModelImpl object but I'm using the Jackson json exporter to generate JSON representations of my models and it's leading to "Infinite recursion (StackOverflowError)". When I debug it, it does seem like my init method the one from AssetModelImpl, as well its getResource() method are looping indefinitely so I'm wondering if what's happening is that the delegate isn't linked properly and the two assets are one and the same so it's basically a class holding itself?
Maybe that doesn't really make sense but any guidance on how to properly extend the AssetModel(Impl) would be greatly appreciated.
Thanks,
Liviu
Beta Was this translation helpful? Give feedback.
All reactions