Customizing Components and Other Elements
When creating your own components or customizing an existing component, it is often easiest (and safest) to reuse existing definitions. The same principles also apply to other elements within AEM, for example, the error handler.
This can be done by copying and overlaying the existing definition. In other words, copying the definition from /libs to /apps/<your-project>. This new definition, in /apps, can be updated according to your requirements.
For example:
-
This involved overlaying a component definition:
-
Create a component folder in
/apps/<website-name>/components/<MyComponent>by copying an existing component:-
For example, to customize the Text component copy:
- from
/libs/foundation/components/text - to
/apps/myProject/components/text
- from
-
-
-
Customizing pages shown by the Error Handler
This case involves overlaying a servlet:
-
In the repository, copy one or more default scripts:
- from
/libs/sling/servlet/errorhandler/ - to
/apps/sling/servlet/errorhandler/
- from
-
/libs path./libs is overwritten the next time you upgrade your instance (and may well be overwritten when you apply either a hotfix or feature pack).- copy the item in
/libsto/apps - make any changes within
/apps
When to use JCR Queries and when not to use them
JCR Queries are a powerful tool when employed correctly. They are appropriate for:
-
real end-user queries, such as fulltext searches on content.
-
occasions where structured content must be found across the entire repository.
In such cases, make sure that queries only run when required. For example, on component activation or cache invalidation (as opposed to, for example, Workflows Steps, Event Handlers that trigger on content modifications, and Filters).
Never use JCR Queries for pure rendering requests. For example, JCR Queries are not appropriate for the following:
- rendering navigation
- creating a “top 10 latest news items” overview
- showing counts of content items
For rendering content, use navigational access to the content tree instead of performing a JCR Query.
Security Considerations
JCR (Repository) Sessions
Use the user session, not the administrative session. This means you should use:
Protect against Cross-Site Scripting (XSS)
Cross-site scripting (XSS) allows attackers to inject code into web pages viewed by other users. This security vulnerability can be exploited by malicious web users to bypass access controls.
AEM applies the principle of filtering all user-supplied content upon output. Preventing XSS is given the highest priority during both development and testing.
Also, a web application firewall, such as mod_security for Apache, can provide reliable, central control over the security of the deployment environment and protect against previously undetected cross-site scripting attacks.
The XSS API cheat sheet contains information that you must know to use the XSS API and make an AEM app more secure. You can download it here:
The XSSAPI cheat sheet.
Securing Communication for Confidential Information
As for any internet application, make sure that when transporting confidential information
- traffic is secured through SSL
- HTTP POST is used if applicable
This applies to information that is confidential to the system (like configuration or administrative access) and information confidential to its users (like their personal details)
Distinct Development Tasks
Customizing Error Pages
Error pages can be customized for AEM. This is advisable so that the instance does not reveal sling traces on internal server errors.
See Customizing Error Pages shown by the Error Handler for full details.
Open Files in the Java™ Process
Because AEM can access many files, it is recommended that the number of open files for a Java™ process be explicitly configured for AEM.
To minimize this issue, development should ensure that any file opened is correctly closed when (meaningfully) possible.
Was this content helpful?
Announcements
Get hands-on with agentic AI.
Explore how AI agents work together through real examples and hands-on practice. Join your local User Group to design an agent workflow with your peers and leave with a practical framework you can apply to your own work.
Find an eventAdobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & EMEA
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & APAC
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Brand Visibility Roadmap Webinar - Americas & EMEA
Preview the Brand Visibility roadmap across Brand Concierge and AEM Sites. Ask live.