Skip to content

Instantly share code, notes, and snippets.

@sgaem
sgaem / PageRedirectServlet.java
Last active February 27, 2024 13:43
The servlet that overrides OOTB of the PageRedirectServlet.java
package com.aem.project.core.servlets;
import com.day.cq.wcm.api.WCMMode;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@sgaem
sgaem / DropDownServlet.java
Created January 12, 2019 13:59
This gist shows the dynamic population of drop down using datasource in AEM.
package com.aem.project.core.servlets;
import com.adobe.cq.commerce.common.ValueMapDecorator;
import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.adobe.granite.ui.components.ds.ValueMapResource;
import com.day.crx.JcrConstants;
import org.apache.commons.collections4.iterators.TransformIterator;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
@sgaem
sgaem / showhidetab.js
Created September 4, 2018 16:01
This JS file is used to hide and show tabs based on drop down selection.
/**
* Extension to the standard dropdown/select component. It enabled hidding/unhidding of tabs based on the
* selection made in the dropdown/select.
*
* How to use:
*
* - add the class cq-dialog-dropdown-tab-showhide to the dropdown/select element
* - add the data attribute cq-dialog-dropdown-tab-showhide-target to the dropdown/select element, value should be the
* selector, usually a specific class name, to find all possible target elements that can be shown/hidden.
package aem.training.core.models;
import aem.training.core.config.GoogleReCaptchaConfiguration;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
package aem.training.core.config;
import org.apache.sling.caconfig.annotation.Configuration;
import org.apache.sling.caconfig.annotation.Property;
/**
* Context Aware configuration for Google ReCaptcha.
*
* @author shivani Date Created: 31 January 2020
package aem.training.core.models;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class SampleJbossApplication extends SpringBootServletInitializer {
@sgaem
sgaem / UserAccountDetail.java
Created May 31, 2019 03:14
UserAccountDetail.java is the implementation of Factory OSGI Configuration.
package com.poc.osgiannotation.core.servlets;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.metatype.annotations.Designate;
@Component(service=UserAccountDetail.class,immediate=true)
@Designate(ocd = UserConfiguration.class,factoy=true)
public class UserAccountDetail {
@sgaem
sgaem / Multifield.js
Last active March 29, 2019 09:49
This Multifield.js is working with all the widgets like drop-down and checkbox functionality.
(function ($, $document) {
var DATA_EAEM_NESTED = "data-eaem-nested";
var CFFW = ".coral-Form-fieldwrapper";
function isSelectOne($field){
return !_.isEmpty($field) && ($field.prop("type") === "select-one");
}
function setSelectOne($field, value){
var select = $field.closest(".coral-Select").data("select");
if(select){
select.setValue(value);
@sgaem
sgaem / DropDownServlet.java
Created January 12, 2019 16:54
This gist demonstrates how to dynamically populate values based on different conditions in AEM.
package com.aem.project.core.servlets;
import com.adobe.cq.commerce.common.ValueMapDecorator;
import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.adobe.granite.ui.components.ds.ValueMapResource;
import com.day.cq.wcm.api.Page;
import com.day.crx.JcrConstants;
import org.apache.commons.collections4.iterators.TransformIterator;
import org.apache.sling.api.SlingHttpServletRequest;