AEM Developer Guide | AEM Query Optimisation
Using AEM to Run SQL2 Queries Effectively
Have you ever needed to locate specific references or properties within AEM?
Assume you have a word with its “colour” property set to green; using SQL2 queries, you can search all nodes along a given path where this property exists.
AEM tools offer three query types, but SQL2 queries provide more accurate results.
A built-in console makes this possible for easy query generation and execution, though some tweaking might be required to achieve optimal outcomes.
If, for instance, you want to locate nodes with their “colour” set to “green,” specify their path, write and execute a query before running your query.
Here’s how it works: start from your chosen node, add conditions, and refine your query using AEM’s user-friendly query builder until your results meet your requirements.
Testing queries in real time through AEM allows for effortless adjustments until they provide exactly what’s wanted.
Simplifying Complex Searches with AEM
AEM excels at managing basic queries efficiently. Since AEM does not use relational databases like SQLite or Oracle, complex query writing might present obstacles.
Nevertheless, AEM still allows you to locate nodes along a specific path and with particular properties.
Are You Searching for Node “sample”? AEM’s query tools can assist in pinpointing nodes where this name exists.
By adding conditions like any node containing “sample,” refine and narrow your results and obtain better matches.
Finding Nodes by User in AEM
Imagine you need to locate all nodes below a specific path created by one particular user in AEM.
Each page they create stores their identity as the creator under the property ‘jcr:createdBy.’
SQL2 queries provide an effective means of quickly searching for all nodes created by, for instance, “admin,” while providing instantaneous updates based on changes, such as users changing to something like “admin1.”
Once run, the results will immediately reflect those conditions you specified.
This feature can help users track edits and understand user interactions within AEM.
Handling Property-Based Queries in AEM
As part of AEM, users may require finding nodes based on specific properties like “lastName.’
For example, consider two nodes with last names such as RAMG.
To narrow your search further, you could use the “like” condition of SQL2 queries to find all nodes containing RAM.
With AEM’s flexibility comes an ability to tailor searches precisely according to criteria that best meet them, making AEM the perfect tool for property searches.
Combining Queries for Advanced Results
AEM shines when used to combine multiple queries for advanced results, creating a powerful search tool.
You can search by property name or even specific user edits.
These combinations provide a flexible way of exploring content and quickly finding what you need.
AEM gives you all the tools required for effective queries involving properties or complex queries involving paths or conditions.
Understanding Components in AEM
Components form the cornerstone of AEM pages; every page in AEM comprises various collections of components grouped to create its content domain.
Impressively, every individual element works independently from one another to form its content domain.
AEM stands out due to its modular nature; should one component fail, its failure doesn’t affect others and vice versa – an invaluable trait of resilience.
This modularity also contributes to making AEM extremely reliable.
Each component in AEM boasts distinctive styling and functionality.
Relying on individual components ensures that when problems do arise, they remain isolated to just that particular component in question.
Where AEM Stores Code and Configurations
Custom code we develop resides within AEM’s apps hierarchy for easy development and innovation, while prewritten Adobe code lives within its lib’s hierarchy.
Keeping custom work distinct under its respective directories is essential for efficient workflow and easy maintenance of clean code separation between teams.
Configuration is integral in AEM, from connecting to Adobe Analytics or Campaign to Launch.
All settings live under the “conf” directory for easy organisation and maintenance of settings for these services.
Ultimately, this ensures everything done within AEM has a designated spot within this structure.
Content Storage in AEM
AEM provides clear directories to organise all types of data.
For instance, “content” holds your pages, experience fragments and assets.
“Home” stores information related to users. Finally, “var” is perfect for temporary storage and API content.
Indexes serve an indispensable function, aiding search functionality.
They reside under the node named ‘oak: index’.
Working with Components in AEM
As soon as a project is created in AEM, an initial selection of core components serves as its starting point – this serves as your “core.”
Adobe encourages leveraging core components instead of building custom ones from scratch, saving time and ensuring compatibility with AEM standards.
Core components are under ‘apps/core/wcm/components.
If you run an older version of AEM (pre-6.5), these components can still be obtained from Adobe’s GitHub repository and installed manually.
How AEM Handles Dialogue, HTML, and Java
Every component in AEM includes three essential elements: dialogues, HTML and Java.
Dialogues enable authors to input texts, images or other content directly.
Java is essential in backend business logic, ensuring that inputs provided through dialogues are rendered adequately on websites.
Best Practices for Component Development in AEM
As much as AEM makes it easy to create components from scratch, copying and customising an existing core component is often best practice.
This approach aligns with Adobe’s documentation and best practices.
For example, when creating a new component, you could copy one from existing designs and rename it before customising it.
This creates a solid base and allows you to adapt quickly to your specific requirements.
Understanding AEM Component Naming
As soon as you start using AEM, one of the first decisions you need to make is regarding component names.
They must reflect that of their associated HTML file inside its folder and should share at least one name with one or more existing HTML files.
It ensures that when AEM calls a component, its HTML rendering correctly represents what AEM requested.
Otherwise, no operation would occur, leading to no visible outputs from AEM.
Structuring AEM Components
AEM supports multiple HTML files within one component for easier complex code development.
Instead of writing lengthy HTML in one file, developers can break it into smaller chunks to optimise performance and increase speed.
This follows a similar idea to Java, in which primary and utility classes can be created to perform various functions.
Within AEM, breaking HTML files up ensures better readability and functionality.
Defining AEM Dialogues
Every AEM dialogue must bear the name ‘cq: dialogue’ as per AEM protocol; this cannot be altered as part of its foundational design.
A dialogue acts as an interface allowing user input that modifies component properties.
As opposed to manually creating dialogue structures from scratch, copying an existing dialogue from another component and customising it accordingly can significantly speed development while guaranteeing consistency in delivery.
Grouping Components in AEM
AEM components belong to groups, making categorisation and management much more straightforward.
For example, multiple components might fall under “Sample Project Content,” while others can be organised under “Sample Project Form.”
AEM recognises its group when adding components to pages, providing seamless organisation within the system.
Understanding AEM Dialogue Fields
Each field in an AEM dialogue serves a specific function, ranging from text inputs and number inputs, checkboxes or path selectors to text fields.
To define text fields specifically, set their property named ‘sling:resourceType’ with appropriate values.
Number fields or path selectors must have their resource type explicitly stated to ensure proper behaviour.
Creating Dynamic Fields in AEM Dialogues
AEM dialogues may include several fields with distinct purposes, such as fields for entering first name, last name and age information.
Text fields allow any character input, while number fields limit to numerical input only.
Path fields enable users to search the AEM repository and select assets quickly.
Implementing AEM Path Selectors
Path fields are pivotal when using AEM dialogues for media asset referencing, enabling users to browse and select images from content repositories for accurate file linking.
By copying the structure of existing path fields, developers can quickly implement them without being confused by complex attributes or attribute definitions.
Understanding AEM Resource Types
Resource types play an essential part in structuring content within dialogues in AEM.
Text, number and path fields rely on resource types for their behaviour.
Selecting an AEM component with appropriate resource type settings ensures accurate rendering.
Relative Paths in AEM
When resolving relative paths, AEM follows a hierarchy. By default, it starts searching within the ‘apps’ hierarchy first.
AEM uses this structured approach to find and apply code efficiently for components if the required resource cannot be located within its “libs” hierarchy.
Rendering Fields in AEM
AEM provides a systematic way for developers to render fields within dialogues.
From text fields and number fields to predefined configurations in its hierarchy, AEM easily ensures proper presentation.
If customisation is needed for any field, AEM allows developers to modify its properties based on individual user requirements.
AEM Dialogue Customisation
AEM allows developers to design dialogues tailored explicitly for an author using resource properties and field types such as checkboxes, colour pickers, autocomplete fields and text areas.
Each AEM field ensures a smooth content editing experience.
Validating Inputs in AEM
AEM provides built-in validation mechanisms to verify that input values conform to specified constraints.
Developers using the AEM framework can set maximum and minimum values, enforce mandatory fields, customise validation messages as needed and set maximum/minimum value limits and enforce mandatory fields as desired.
JavaScript/jQuery scripting capabilities may also be employed for further customisation purposes.
AEM Component Development
Developing components in AEM requires understanding how different resource types, paths, and validation mechanisms interact.
AEM’s robust framework ensures seamless content structuring regardless of whether modifying existing components or developing entirely new ones.
Developers can utilise AEM’s capabilities to enhance authoring experiences.
Exploring AEM Components
An essential aspect of AEM is validating and customising fields effectively.
For instance, assign each field its class for the age field to implement custom validation so you can easily recognise it when writing validation code.
At AEM, classes are essential as they offer greater flexibility than IDS.
Though IDS may also be utilised, the focus should be on exploiting unique classes or attributes like data for efficient customisation.
Imagine you’re working with a sample-age field. By giving it its class name, such as ‘sample-age’.
It becomes easier to isolate its properties and set validation rules based on imported values, while providing specific validation rules if no value exists yet (if no imported values exist yet, use parameters accordingly).
Customising Checkboxes and Resource Types in AEM
AEM allows you to design and personalise components, including checkboxes.
To build one from scratch, copy code from an equivalent field before adapting it as necessary.
Resource types come into play here as they indicate where to locate your component’s source code and other files that make up its codebase.
Resource types make creating dialogue components in AEM simpler.
Utilising them, you can explore the core properties of checkboxes or fields, adjust configuration settings accordingly and apply customisations explicitly tailored for you.
Keep in mind that AEM follows a structured hierarchy.
Paths in either of its directories (apps/libs) define where code will be searched and implemented, helping you effectively manage resource types and field configurations by comprehending this sequence of operations.
Unlocking Advanced Features with AEM
AEM provides you with a robust platform that allows you to explore advanced features, including customising text and checkbox components and exploring resource types that provide access to the underlying code, while exploring possible configurations of components.
Implementing fields within AEM, such as checkboxes, radio buttons, and text fields, requires careful thought to make them user-friendly and compatible with existing components.
AEM provides greater control in managing dialogues and attributes, simplifying the construction components that meet user requirements.
It is more straightforward since AEM employs a structured approach to searching ‘apps’ and ‘libs’ directories.
Ensuring that all configurations are aligned precisely is key for successful customisations and that you can progress without issue.

Sai Susmitha
Author