Hi i am new to AEM, and stuck with one issue: I want use the request object of DemoModel, into CallToActionModel to call one of the util methods, but this does not seems to work, can anyone please help with this, below is the code snippet
@Model(adaptables = { SlingHttpServletRequest.class,
Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name =jackson, extensions = json)
public class DemoModel extends WebComponentModel{
@SlingObject
private SlingHttpServletRequest request;
@ChildResource
@Expose
private List<DemoModelList> site;
}
Model(adaptables = { SlingHttpServletRequest.class,
Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class DemoModelList extends WebComponentModel {
@ChildResource
@Expose
private List<CallToActionModel> links;
}
@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class CallToActionModel extends WebComponentModel {
@Inject
private SlingHttpServletRequest request;
@Default(booleanValues = false)
@ValueMapValue
@Expose
@Getter
@Setter
private boolean isSiteCheck;
@Override
@PostConstruct
protected void init() {
isDealerSite = isSiteCheck && AEMUtils.isSite(request);
super.init();
}
Views
Replies
Total Likes
If both the components are part of same page, then same request object will flow through entire page. You don't need to pass it from one Model to another.
Can you share more details about error if any or what exactly not working.
yes they are part of same page but different classes, so what code change is required to achive that, i just want the isSiteCheck to become true when both the conditions are met, but i am getting request object as null.
I tried that as well but still object is coming as null
Hi @c-shjain
Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Please use following in CallToActionModel and give it a try:
@ScriptVariable
private SlingHttpServletRequest request;
You can also refer to https://techrevel.blog/2017/03/18/sling-model-annotations/. It has various code sample on how to get objects in Sling Models
1. Refrain from using SlingHttpServletRequest.class, Resource.class together. Details are there in blog
2. Refrain from using @Inject. Details available in blog
Even after changing the annotation to @ScriptVariable, the object is still null.
@c-shjain Did you find the suggestions from users helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Nothing worked for me so i changed the complete approach and used 2 different classes to achieve this.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies