Base AJAX Component
DeprecatedAvailable since version 1.0.0
Why is this deprecated?
An robust alternative that supersedes this feature is the open-source Sling Dynamic Include (SDI) library. SDI has been contributed to the Apache Sling project and provides: SSI, ESI, and JSI (Javascript-Side Include; which is effectively what this ACS AEM Commons feature provided) capabilities.
We recommend evaluating Sling Dynamic Include before using this feature.
Purpose
Provide a simple extension point for turning “normal” components into components that are pulled into the page via AJAX.
How to Use
- Requires jQuery 1.8+
- Install the ACS AEM Commons package
- Make sure the
acs-commons.components
clientlib is included (preferably at the end of the page) - On any existing component definition; set the component’s sling:resourceSuperType to be
acs-commons/components/content/base/ajax
-
Optionally, set the property
ajaxSelectors
on thecq:Component
node. This selector is used to resolve the script for thiscq:Component
- If this value is not set, ‘ajax’ is default
-
Rename the default component JSP to be
ajax.jsp
(or whatever your custom ‘ajaxSelectors’ property specifies)-
Ex.
apps/mycomponent@ajaxSelectors: nocache
would use/apps/mycomponent/nocache.jsp
to render the AJAX request for the resource. -
Ex.
apps/mycomponent@ajaxSelectors: foo.bar
would use/apps/mycomponent/foo/bar.jsp
to render the AJAX request for the resource.
-
- Either
<cq:include path="foo" resourceType="acme/components/text"/>
or drag the component into a ParSys
Show loading indicator while AJAX request is loading
The Base AJAX component comes with a default loading indicator, generated by spin.js. To use this loading indicator, you need to do the following steps
- Make sure the
acs-commons.components.ajax.loading-indicator
clientlib is included (preferably at the end of the page) - Set the property
ajaxLoadingIndicator
on thecq:Component
node toacs-ajax-loading-indicator
Notes
-
If you leave a default script with the same name as the component, the ajax functionality will be ignored and the component will render as usual.
- Ex. /apps/mycomponent/mycomponent.jsp
-
You CANNOT include one AJAX’d component in another; only the first will load. This is done by checking for the existence of the string ‘data-ajax-component’ in the AJAX result.
Example
Default configuration
-
/apps/geometrixx/compoments/title
- sling:resourceSuperType:
acs-commons/components/content/base/ajax
- sling:resourceSuperType:
-
/apps/geometrixx/compoments/title/title.jsp
- moved to:
/apps/geometrixx/compoments/title/ajax.jsp
title.jsp
will no longer exist
- moved to:
Default configuration including loading indicator
-
/apps/geometrixx/compoments/title
- sling:resourceSuperType:
acs-commons/components/content/base/ajax
- ajaxLoadingIndicator:
acs-ajax-loading-indicator
- sling:resourceSuperType:
-
/apps/geometrixx/compoments/title/title.jsp
- moved to:
/apps/geometrixx/compoments/title/ajax.jsp
title.jsp
will no longer exist
- moved to:
Customized selector configuration
-
/apps/geometrixx/compoments/title
- sling:resourceSuperType:
acs-commons/components/content/base/ajax
- ajaxSelectors:
nocache
- sling:resourceSuperType:
-
/apps/geometrixx/compoments/title/title.jsp
- moved to:
/apps/geometrixx/compoments/title/nocache.jsp
title.jsp
will no longer exist
- moved to: