sling-models

Get .model.json as String

六眼飞鱼酱① 提交于 2021-02-08 04:59:24
问题 I wonder if there is an easy way to get a String with the result of a sling content exporter in AEM. In my current usecase I need the content of a component's .model.json output in the component's htl file and sending an additional request is obviously not a good idea. Any hints on how I can get the data? 回答1: After some reading and experimenting, I found a way to do it: Add a dependency to the following package in your pom: <dependency> <groupId>com.fasterxml.jackson.core</groupId>

How to call Sling Model Method with input parameter AEM

半城伤御伤魂 提交于 2020-04-07 09:16:43
问题 I am having a scenario in which i want to call a sling model with input parameter. For this i have a code like this <div data-sly-use.model3="${'com.bhf.aem.sling.models.Test' @ colour='red'}"> </div> But I want to call a method in sling model twice with two different parameters .Is it possible with sling models? Any Help!!! 回答1: From AEM 6.3 there is a new HTL feature that allows to do this. In the data-sly-include and data-sly-resource you can now pass requestAttributes in order to use them

How to call Sling Model Method with input parameter AEM

六眼飞鱼酱① 提交于 2020-04-07 09:16:12
问题 I am having a scenario in which i want to call a sling model with input parameter. For this i have a code like this <div data-sly-use.model3="${'com.bhf.aem.sling.models.Test' @ colour='red'}"> </div> But I want to call a method in sling model twice with two different parameters .Is it possible with sling models? Any Help!!! 回答1: From AEM 6.3 there is a new HTL feature that allows to do this. In the data-sly-include and data-sly-resource you can now pass requestAttributes in order to use them

SlingModels: Can I inject the SlingHttpServletRequest when adapting from Resource?

℡╲_俬逩灬. 提交于 2019-12-24 06:20:34
问题 I am new to SlingModels and the annotations aren't very clear yet. I am currently trying to transform some basic foundation components from AEM 6.2 to using SlingModels instead. For the image component the foundation JSP uses the SlingHttpServletRequest to set the ImageDoctype. So I tried the following: @Model(adaptables = {Resource.class}) public class ImageModel { @SlingObject private SlingHttpServletRequest request; @SlingObject private Resource resource; } But with this the request is

Sling model unit tests: mock currentPage in SlingHttpServletRequest

冷暖自知 提交于 2019-12-23 03:57:12
问题 I am having some trouble testing a Sling model: the currentPage is not getting injected for some reason. My Sling model looks like this: @Model( adaptables = { SlingHttpServletRequest.class, Resource.class }, resourceType = MyModel.RESOURCE_TYPE) public class MyModel { public static final String RESOURCE_TYPE = "myproject/components/renderer"; @Inject private Page currentPage; // Model methods, etc. } I writing some JUnit tests for it, like so: @RunWith(MockitoJUnitRunner.class) public class

Resource Resolver returned as null via sling models

匆匆过客 提交于 2019-12-13 09:40:00
问题 Resource Resolver is being returned as null while injecting through sling models, let me know if anything I am missing : I tried with : @Model(adaptables = Resource.class) public class Navigation { @Inject @Source("sling-object") private ResourceResolver resourceResolver; } I also tried with: @Model(adaptables = Resource.class) public class Navigation { @Inject private ResourceResolver resourceResolver; } In both cases it was being returned as null and throwing a null pointer exception. Let

AEM 6.3 - Multifield using Sling Model

三世轮回 提交于 2019-12-11 06:09:57
问题 I am trying to create a Coral UI 3 multifield and use Sling Models. Here is how the dialog looks like: Here is the code : package com.aem.sites.models; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Named; import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Model; import org.apache.log4j.Logger; import com.aem.sites.models.Header; @Model