Sightly syntax to retrieve crx/de properties in jsp/html page - aem

I would like to retrieve some properties e.g. jcr:created using Sightly or any related syntax for the panel component in AEM adaptive forms. 1
The previous Sighlty syntaxes that I have attempted to retrieve the crx/de properties include:
${properties.jcr:created}
${pageProperties\[jcr:created\].getTime.toString}
${guidePanel.jcr:created}
${resource.jcr:created}]
I have tried the following syntaxes but unable to retrieve the value from the property and in worst cases, the component may not be rendered on screen.
I have looked up on Adobe forum sites and past stackoverflow questions that other people may have asked. I have tried the solutions and given answers but was unable to achieve the result. I would greatly appreciate for any help or sharing of applicable knowledge if you have encountered similar issues or previously attempted to solve similar problems. Thank you!

You can always create Use class in Java or Javascript to access these properties, it's cleaner and testable. Better than that, you can use Sling Models which are more readable and easier to implement, here is a good presentation about it https://www.slideshare.net/accunitysoft/understanding-sling-models-in-aem

Properties of resources are readable without any extra definitions needed.
So you might want to check what resource is handled in your component by adding this:
${resource.path}
Then you can check the returned path in CRXDE if there really is a jcr:created property available at this path - which should be the case if you are accessing a resource that has a proper sling resource type. Then this call should give a valid return value:
${resource.path} ___ created:
${properties.jcr:created.getTime.toString}
If the path is not displayed as well, then it would help if you could post
the repo path of the content resource you are processing
the sling:resourceType
the path to the component's ht(m)l file that you are using

Related

AEM-6.4 Original Value of sling:resourceSuperType for /libs/foundation/components/redirect

I have accidentally make changes to the sling:resourceSuperType value of /libs/foundation/components/redirect in CRXDE. I have tried to google from AEM site like https://www.aemcomponents.dev/ to get the answer, but still no avail.
I would like to know the original value that set to the sling:resourceSuperType. It will be good if someone can share the value here, or will even better if able to share any other site and guide that can get the original properties of each AEM components.
foundation/components/page is the sling:resourceSupertype for /libs/foundation/components/redirect
(The 'redirect' component refers to a page. Hence, its super-type is 'page')
Also you can always copy your jar with a new name and port and extract it. It will create a vanilla system and there you can check it.

Keycloak templates available variables

I'am googling for a while in order to find a documentation of all available say "variables" I can use in the various Keycloak templates.
by variable I mean all the ${xxx.yyy} things I can use to inject some dynamic values inside the template.
Through the documentation I can find here and there some of them (like ${user.attributes} or ${url.resourcesPath}) but are there others than these ?
Does anyone have a reference link ?
Many Thanks
You can look for the template providers in Keycloak's code.
All the templates are "ftl" files filled with a map called "attributes". Keycloak has a couple of classes which fill those templates with Beans depending on the page or action as CharlyP mentioned. For example:
FreeMarkerEmailTemplateProvider class fills the email templates.
FreeMarkerLoginFormsProvider class fills the login templates.
I did not find any easy to use documentation but I found the Keycloak Javadocs which can be helpful when you look for the *Bean classes of this documentation. These classes seem to be the ones available in most of the templates. And their public methods will match the available properties you can use in the templates.
For example:
You want to know the properties available for the variable url you can check the class UrlBean in the documentation and you will find for example a method getLoginUrl. This means you can access the property url.loginUrl.
That's all I could find for the time being. Hope it will be helpful...

AEM/Sling: How do I implement dynamic sling selector?

TLDR: I want setup an AEM page that accepts firstname and lastname as parameter using an SEO friendly URL.
Going to www.host.com/mycontent.richard.williams.html will display information relevant to Richard Williams.
If I go to www.host.com/mycontent.john.smith.html, the page will display information relevant to John Smith.
SEO friendly example: www.host.com/mycontent.richard.williams.html
not SEO friendly example: www.host.com/mycontent.html?firstname=richard&lastname=williams
So I've been following this guide (not sure if this is the best example/guide to help me): http://www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/
And while it works well for my the example
#SlingServlet(resourceTypes="geometrixx/components/hompepage", selectors={"firstname","lastname"}, extensions="html",methods="GET", metatype=true)
I am trying to make it dynamic.
At the moment, I can only access the servlet if access via: http://localhost:4502/content/geometrixx/en.firstname.lastname.html
I want to make firstname and lastname dynamic parameters/selectors. Like if for example I want to pass the values "richard.williams", I can then use: http://localhost:4502/content/geometrixx/en.richard.williams.html
if I try to use http://localhost:4502/content/geometrixx/en.richard.williams.html right now, I get a blank page.
So basically I want to use selectors for passing parameter values to my page.
Any ideas how this can be done?
ps. At the moment, I only testing/experimenting in my local instance of AEM.
Selectors in sling don't provide the functionality of placing variables in the URL path. i.e. you cannot add {pathParam} like in Spring to sling servlet URL.
In general, selectors are not recommended to be used like an input to a function. They are to be used more like file extensions.
For eg. A request to /mycontent.html returns the same resource as /mycontent.mobile.html. The only difference being, the latter requests for a mobile friendly version.
Request params on the other hand serve the purpose of providing inputs to the servlet.
I cannot think of any direct way to attach a servlet to dynamic paths in sling. You can try using suffix, they are cacheable in the dispatcher, but I can't comment on the SEO friendliness of using suffix.
Consider this URI - /mycontent/user.json/john/smith
Register a servlet using the path /mycontent/user and you can use
String[] names = request.getRequestPathInfo().getSuffix().split(suffix, '/')
to retrieve the suffix contents.
Take a look at answers in this question. Sling ResourceProvider and integrating with jax-rs are other ways you can accomplish this.
Technically this would be feasible with the use of OptingServlet (see https://sling.apache.org/documentation/the-sling-engine/servlets.html#optingservlet-interface)
Your accepts method could easily recognise the expected resourceType and react appropriately.
As mentioned in the docs this approach is discouraged and the solution proposed by Subhash to use suffixes seems way more elegant.
You can create a components which reads selector from the request and add that compoent to en.html

where does "request" come from in CQ5?

I am new to CQ5.
While I was trying to follow the official guide of how to create a website at
[https://docs.adobe.com/docs/en/cq/5-6-1/howto/website.html], the following code confused me.
Iterator<Page> children = rootPage.listChildren(new PageFilter(request));
I did not find any reference of "request". Can someone tell me where it comes from?
Thanks in advance.
Well request is an instance of the HttpServletRequest that is available implicitly in any JSP file. (Full list here).
Hence you can use them directly without explicitly declaring them.
In AEM (CQ5), apart from the JSP implicit objects, you can get quick access to few AEM, Sling and JCR specific objects by including the global.jsp file in your JSP as shown below.
<%#include file="/libs/foundation/global.jsp"%>
This entire list of objects and tag libraries that would be available through your global.jsp can be found here.

Google Rich Snippets warnings for hCard

I get the following errors from the Google Rich Snippet Tool for my website http://iancrowther.co.uk/
hcard
Warning: This information will not appear as a rich snippet in search results results, because it seems to describe an organization. Google does not currently display organization information in rich snippets
Warning: At least one field must be set for Hcard.
Warning: Missing required field "name (fn)".
Im experimenting with vcard and Schema.org and am wondering if I'm missing something or the validator is playing up. I have added vcard and Schema.org markup to the body which may be causing confusion. Also, I am making the assumption I can use both methods to markup my code.
Update:
I guess with the body tag, I'm just trying to let Google discover the elements which make up the schema object within the page. I'm not sure if this is a good / bad way to approach things? However it lets my markup be free of specific blocks of markup. I guess this is open to discussion but I like the idea of having a natural flow to the content that's decorated in the background. Do you think there is any negative impact? I'm undecided.
I am in favour of the Person structure, this was a good call as this is more representative of the current site content. I am a freelance developer and as such use this page as my Organisation landing page, so I guess I have to make a stronger decision of the sites goals and tailor the content accordingly, ie Organisation or Person.
I understand that there is no immediate rich snippet gains, but im a web guy so have a keen interest in these kind of things.
With schema testing, I find it easiest to start from the most obvious problem, and try to work our way deeper from there. Note, I have zero experience with hcard, but I don't believe the error you mentioned actually has anything to do with your hcard properties.
The most obvious problem I see, is that your body tag has an itemtype of schema.org\Organization. When you set an itemtype on a dom element, you are saying that everything inside of that element is going to help describe that itemtype. Since you've placed this on your body element, you are quite literally telling Google that your entire page is about an organization.
From the content of your page, I would recommend changing that itemtype to schema.org\Person. This would seem to be a more accurate description. Once you make that change and run the scanner again, you may see more errors relating to the schema and we can work through those too (for example, you'll probably need to set familname and givenName).
With all of that said, you should know that currently there are no rich snippets that you will gain from adding this schema data. Properly setting this up on your page, is only good to do, especially since we don't know what rich snippets Google or others will expose in the future, but currently you won't see any additional rich snippets in Google search results from adding these tags. I don't want to discourage you from setting this up properly but I just want to set your expectations.