I have a property with the path to required page in a content file
...
<some_block
...
sling:resourceType="some_path_to_some_component"
somePage="some_path_to_page"
.../>
...
suitable HTL component some-component.html
<div data-sly-use.some_model="org.example.SomeModel">
...
</div>
and model class SomeModel.java
package org.example;
...
import com.day.cq.wcm.api.Page;
...
@Model(adaptables = { SlingHttpServletRequest.class, Resource.class },
defaultInjectionStrategy = DefaultInjectionStrategy.REQUIRED)
public class RelatedContentBlock {
@ValueMapValue
private Page somePage;
...
}
I easily can get the required Page object using @Inject and @Via annotations, but why can't I grab it with the @ValueMapValue annotation? I tried to use all the possible variants including via attribute and so on. And yes, I can get it from the pageManager, but what's wrong with @ValueMapValue?
Thanks in advance!
The documentation that you linked of the
@ValueMapValue
annotation has the answer you are looking for:The important part is:
A
Page
is not aValueMap
. Therefore, this annotation can not be used to inject a page.This annotation is mainly used to inject page properties. Because page properties (or resource properties for that matter) are stored in a
ValueMap
. That is why you can use the@ValueMapValue
annotation to inject thejcr:title
of a page:This is equivalent to (pseudo code):