By adding the class name and an optional instance name to the content descriptor for an annotated component, we can eliminate the need to use the component tag in the CQ library. The component can instead be instantiated directly from the define objects tag instead of requiring the developer to include an additional tag in the component JSP. The define objects tag in the CQ library will then be updated to include this logic:
final Component component = request.getComponent();
if (component != null) {
final ValueMap properties = component.getProperties();
final String className = properties.get("className", "");
if (!className.isEmpty()) {
final String instanceName = properties.get("instanceName", "");
try {
final Object instance = Class.forName(className).getConstructor(ComponentRequest.class)
.newInstance(request);
pageContext.setAttribute(instanceName, instance);
} catch (Exception e) {
LOG.error("error instantiating component = " + className, e);
}
}
}
By adding the class name and an optional instance name to the content descriptor for an annotated component, we can eliminate the need to use the component tag in the CQ library. The component can instead be instantiated directly from the define objects tag instead of requiring the developer to include an additional tag in the component JSP. The define objects tag in the CQ library will then be updated to include this logic: