Hi there,
I am trying to convert my components over to the HTL/Sightly instead of JSP, and I'm running into a road block.
I'd prefer to do the HTL using Javascript-Use API instead of Java-Use because I am more familiar with JS.
My new JS code below errors out:
"Can't find method com.myproject.aem.util.GlobalUtils.userCanReadRedirectTarget(java.lang.Class,org.mozilla.javascript.Undefined).
Any ideas why?
In the old JSP, I have this:
boolean isUnlocked = GlobalUtils.userCanReadRedirectTarget(resourceResolver, linkPath);
if(!isUnlocked) {
// do something here
}
In the new JS file, I have this:
"use strict";
var GlobalUtils = Packages.com.myproject.aem.util.GlobalUtils;
var ResourceResolver = Packages.org.apache.sling.api.resource.ResourceResolver;
use(function() {
var linkPath = properties.get("linkPath");
var isUnlocked = GlobalUtils.userCanReadRedirectTarget(ResourceResolver, linkPath);
return {
isUnlocked: isUnlocked
};
});
Thanks in advance!
Solved! Go to Solution.
Views
Replies
Total Likes
Hi
You can directly use resourceResolver.
e.g
var resourceResolver = resource.getResourceResolver();
let me know if it helps.
Thanks
Dipti
Views
Replies
Total Likes
Hi
You can directly use resourceResolver.
e.g
var resourceResolver = resource.getResourceResolver();
let me know if it helps.
Thanks
Dipti
Views
Replies
Total Likes
Genius - that worked perfectly - thank you! Is there any documentation that explains this a little better? This seems to be the only documentation out there: https://docs.adobe.com/docs/en/htl/overview.html
Views
Replies
Total Likes
gjv wrote...
Genius - that worked perfectly - thank you! Is there any documentation that explains this a little better? This seems to be the only documentation out there: https://docs.adobe.com/docs/en/htl/overview.html
You SHOULD be able to use the ResourceResolver directly without needing to define it like Dipti did...
// just an example, "resolver" is the name of the globally defined ResourceResolver var userId = resolver.getUserID();
See full documentation on available global objects in HTL[1]. If you're looking for what you can do with the ResourceResolver, check the full Java documentation for that class[2].
So in your JS file, you could do something like:
"use strict"; var GlobalUtils = Packages.com.myproject.aem.util.GlobalUtils; use(function() { // ...whatever you were going to use GlobalUtils for here... return { "userId": resolver.getUserID(); // just an example }; });
[1] https://docs.adobe.com/docs/en/htl/docs/global-objects.html
[2] https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/org/apache/sling/api/resource/ResourceRes...
Views
Replies
Total Likes
HI,
Will I be able to use the same in scripts written in GuideBridge API.?
and how should I import java APIs in js file.?
Views
Replies
Total Likes
Views
Likes
Replies