How to fetch current page in sling model
I created some pages with hierarchy like
- Home page
- Men
- Watches
- Smart watch
- Analog watch
- Shoes
- Sports shoes
- Formal shoes
- Watches
- Women
- Watches
- Smart watch
- Analog watch
- Shoes
- Sports shoes
- Formal shoes
- Watches
- Men
How can I fetch current page, that is, 'Home page' into my sling model? Also how to get the childPages i.e 'Men' and 'Women', grandChildPages i.e 'Watches' and 'shoes' of both childPages, and grandGrandChildPages i.e 'Smart watch', 'Analog Watch', 'Sports shoes' and 'Formal shoes' in same sling model?
do you know?
how many words do you know
See also questions close to this topic
-
Placing a component inside of another in AEM 6.5.11
In HTL it is possible to insert a component inside of another componet by using
<sly data-sly-resource="${ @path=somePath, resourceType='path/to/other/component' }"></sly>
. Is there a way to do the same thing in React?
I have tried to use the '@adobe/aem-react-editable-components' package but I haven't had much luck.
-
Pass data to sling model
Is it possible to pass a string or data that is retrieved in an Ajax call to sightly html? I have a 3rd party response in Ajax but I am trying to make the html look prettier by not using script tags. Hence I am planning to write pojos. But the call to the 3rd party will be an Ajax call. Is there a way to bind the Ajax response to sightly html ?
-
How to run Garabge Collection of BlobStore in Jackrabbit Oak?
Using Oak version 1.42 (with java 17), I created a segment NodeStore, backed by a FileBlobStore, like this:
FileBlobStore fileBlobStore = new FileBlobStore("…"); SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions().setEstimationDisabled(true); FileStore fileStore = FileStoreBuilder. fileStoreBuilder(new File("…")). withBlobStore(blobStore). withGCOptions(gcOptions). build(); Repository repository = new Jcr(new Oak(nodeStore)).createRepository()
Then, I create a blob and later I delete it.
The file associated to the blob is still on the file system, and, in my understanding, a garbage collection is needed in order to actually have it removed.
What's the proper way to run the Garbage Collector?
By reading the documentation - and taking into account that the whole thing is NOT run within an Osgi container - it seems that you should call
MarkSweepGarbageCollector#collectGarbage(false)
, but it's not clear to me what are supposed to be the arguments of the constructor (or whether I can get a reference to an instance from some other data structure) - for instance:MarkSweepGarbageCollector garbageCollector = new MarkSweepGarbageCollector( new SegmentBlobReferenceRetriever(fileStore), blobStore, executor, "some path…", 10, // do not have any idea of what this parameter is and what is supposed to be set 1, // are these millis? Or millis from epoch? No idea… null) // no idea what it is this - but it's allowed to be null
This way the blob is NOT deleted - with very little surprise, given that it's unclear to me what the parameters exactly are, and the exact purpose/meaning of some phases (e.g. the blobs are "marked", but I wasn't able to find out what this "mark" means - even by looking at the code…).
I have also tried to call
fileStore.fullGC();
beforecollectGarbage
(thinking that maybe the blob wasn't deleted because of some "stale" data), but with no luck.Maybe the blob is not deleted because it's referenced in the versions history?
If so, what's the proper way to get rid of the blob - firstly delete the version history (how?) and then run the garabage collection?
I did some more investigations, and I also created a mini-program that replicate the issue:
- you can find the program here on github
- by following the program flow step-by-step, imo the issue is that, in the "mark" phase (that is when the GC looks for blobs that are actually still "in use"), the deleted blob reference is still there, i.e. it is still present in the
BinaryReferencesIndex
; therefore, it is marked, and consequently, begin both marked and available, it is not even considered a "candidate" for sweeping.
I think that maybe this could have something to do with the way I add the blob: code follows, please refer to the above github for full context:
Node rootFolder = session.getRootNode(); Node fileNode = rootFolder.addNode(temporaryFile.getName(), "nt:file"); fileNode.addMixin("mix:referenceable"); Node fileContentNode = fileNode.addNode("jcr:content", "nt:resource"); fileContentNode.setProperty("jcr:data", ""); session.save(); Blob blob = nodeStore.createBlob(FileUtils.openInputStream(temporaryFile)); NodeBuilder rootBuilder = nodeStore.getRoot().builder(); NodeBuilder fileContentNodeBuilder = getNodeBuilder(fileContentNode, rootBuilder); fileContentNodeBuilder.setProperty("jcr:data", blob); nodeStore.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); session.save();
-
How to display a json response mapped pojo in sightly
I have a sling servlet that invokes a 3rd party api and fetches a json response. I have mapped the json response to a pojo class using Jackson. I now have to display this dynamically fetched and mapped response in sightly. How do i do that? I am stuck after the response mapping
-
Get ResourceResolver From ResourceResolverFactory, but the ResourceResolver is not able to get Resource by given path
Given siutation like this, author click publish (activate) a page Then I have following listener to handleEvent
public class ArticleContentActivationEventHandler implements EventHandler { private static final Logger LOGGER = LoggerFactory.getLogger(ArticleContentActivationEventHandler.class); private static final String ARTICLE_PAGE_TEMPLATE = "/conf/myproject/settings/wcm/templates/article-template"; @Reference private ResourceResolverService resourceResolverService; @Override public void handleEvent(Event event) { ResourceResolver resourceResolver = null; try { resourceResolver = resourceResolverService.getServiceResourceResolver(); String resourcePath = getResourcePath(event); Resource resource = resourceResolver.getResource(resourcePath); //the resource is null, the resource path is /content/myproject/us/en, //resourceResolver is not able to resolve it somehow for (Iterator<Resource> it = resourceResolver.getResource("/content/myproject/us/en").getChildren().iterator(); it.hasNext(); ) { Resource r = it.next(); String s = r.getPath(); String t = r.getResourceType(); } if (resource.isResourceType("cq:Page")) { Resource jcr_content = resource.getChild("jcr:content"); ValueMap vm = jcr_content.getValueMap(); String template = null; if (vm.containsKey("cq:template")) { template = PropertiesUtil.toString(vm.get("cq:template"), ""); }
and below is the interface:
public interface ResourceResolverService { ResourceResolver getServiceResourceResolver() throws LoginException; void closeResourceResolver(ResourceResolver resourceResolver); }
and the impl class:
@Component(service = ResourceResolverService.class, immediate = true) public class ResourceResolverServiceImpl implements ResourceResolverService { @Reference private ResourceResolverFactory resourceResolverFactory; Logger logger = LoggerFactory.getLogger(ResourceResolverServiceImpl.class); @Activate protected void activate() { logger.info("*** Activating Service ResourceResolverServiceImpl"); } @Override public ResourceResolver getServiceResourceResolver() throws LoginException { final Map<String, Object> param = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) "getResourceResolver"); //the ResourceResolver returned here may got some issue? return resourceResolverFactory.getServiceResourceResolver(param); } @Override public void closeResourceResolver(ResourceResolver resourceResolver) { resourceResolver.close(); } }
I do have the osgi config setup by following tutorial http://www.aemcq5tutorials.com/tutorials/resourceresolver-from-resourceresolverfactory/
But in my actually even handler class, it never successfully resolved resource resourceResolver is not able to resolve /content/myproject/us/en , resourceResolver keep give me null value
Could anyone experienced this suggest me some code sample to resolve my issue? thanks
-
AEM slingmodels - why do we need unused adaptables in each model? Why need both Resource & SlingHTTPRequest?
I am working on a project where every model has this line:
@Model(adaptables = { SlingHttpServletRequest.class,Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
In my understanding:
- If Resource or SlingHTTPRequest is not to be used, this dependency injection must be removed from the model
- SlingHTTPRequest can help obtain resource with the use of .getResource method anyway, so using SlingHTTPServeltRequest class alone, with required dependencyInjectionStrategy should be sufficient, and Resource class as an adaptable is never needed?
Please share your thoughts. Thanks in advance!