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

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

Related

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

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

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...

Netsuite - Dynamically determine domain url

I have been researching for quite a while now about how to dynamically determine the domain url of a netsuite account.
In general I have seen developers hardcoding domain url to "https://system.na1.netsuite.com" or "https://system.netsuite.com" in portlets.
But nobody determines it dynamically.
This in general is a bad practice(although I know Netsuite redirects) and I presume there should be way to determine the correct URL.
Can anyone help in this?
Depending on what you're trying to find the URL for, you can use nlapiResolveURL to dynamically generate the URL for several different NetSuite objects (Suitelets, records, etc). I suggest investigating that function to see if it fits your needs.
Another options is to check the current environment.
You can use nlobjContext to get the environment. Below is the code snippet
var url = 'sandboxurl';
if(nlapiGetContext().getEnvironment()=='PRODUCTION'){
url = 'productionurl';
}
Hope it helps
Depending on your needs, you may simply be better using relative urls. If you use window.location, anything that starts with a / is a relative location: How do I set window.location to a specific path (without a host)? has a good example.
If there is a specific example of what you are using the url for, we might be able to help more!

GWT Dynamic String Internationalization

Can someone explain how to use this feature. i'm trying to search for an example on the web but not getting it. Also, if at run time, the user wants to change language, how to do so??
According to docs, you can
either specify "locale" GET parameter in your URL, for example:
http://www.domain.com/application.html?locale=fr_CA
or add meta tag to your host HTML page, for example:
You may find complete internationalization example here - it uses locale get parameter approach.
As far as I understand, there's no way to change localization without GWT module re-loading (see here for details).
Both these approaches are static. But for the dynamic approach, this is very hard. Based on the current user's locale, change the ui rendering is NOT that easy...
If any

How to extract labels from Symfony forms I18n Extract Task

I am quite aware that the extract task accepts application as a parameter, and thus one can't expect it too look into the forms folder.
However, I referred the link (below) and tried a couple of ways:
1. defining my proxy __() method
2. including the I18n helper in App Configuration
However, both aren't working.
Can anyone tell me how to extract these from the form classes?
Thanks
http://groups.google.com/group/symfony-devs/browse_thread/thread/1d034f5f7367fe0c
You need to use the i18n helper and add the translated strings manually to your XML/XLIFF files. The translations themselves work, it's just the i18n:extract task that doesn't look inside form classes so it has to be done manually. I hope they add this feature in Symfony 2.0.
See the first few paragraphs here: http://www.symfony-project.org/forms/1_4/en/08-Internationalisation-and-Localisation
There's a way to extract it altough it's not recommended by the developers:
In lib/i18n/extract/sfI18nApplicationExtract.class.php add:
$this->extractFromPhpFiles(sfConfig::get('sf_lib_dir').'/form');
to function extract()
In your form class's configure method add:
sfLoader::loadHelpers('I18N');
This way you can use the __() function in your form class.
I'm currently testing it. Will share my findings.