Remove component from Page model json | Community
Skip to main content
Level 3
March 20, 2023

Remove component from Page model json

  • March 20, 2023
  • 1 reply
  • 1614 views

I have a requirement to remove the Column component and all its child component JSON from page model JSON if it contains a specific property set as "TRUE". 

 

I am trying to check for this property in Column Component Sling Model Exporter and setting the getExportedItems as null. Still, it does not remove the component and its child from the page model JSON.

 

package com.colorful.core.models; import com.adobe.cq.export.json.ComponentExporter; import com.adobe.cq.export.json.ContainerExporter; import com.adobe.cq.export.json.ExporterConstants; import lombok.Getter; import lombok.NonNull; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Exporter; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; import java.util.Collections; import java.util.Map; import static com.colorful.core.models.ColumnComponentExporter.RESOURCE_TYPE; @Model(adaptables = SlingHttpServletRequest.class, resourceType = RESOURCE_TYPE, adapters = {ColumnComponentExporter.class, ContainerExporter.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) @Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) public class ColumnComponentExporter implements ContainerExporter { protected static final String RESOURCE_TYPE = "colorful/components/column"; @ValueMapValue(name = "exportThisComponent") private boolean exportThisComponent; @NonNull public String getExportedType() { return RESOURCE_TYPE; } public Map<String, ? extends ComponentExporter> getExportedItems() { if (!exportThisComponent) { return Collections.emptyMap(); } return null; } @NonNull public String[] getExportedItemsOrder() { return new String[0]; } }

 

 

How can I remove this column component and its child from page model JSON?

@debal_das @arunpatidar @santoshsai 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

arunpatidar
Community Advisor
Community Advisor
March 20, 2023
Level 3
March 20, 2023

Using @JSONIgnore I can only remove specific properties from JSON.

But here I am trying to remove the entire "container" component object and its child from .model.json of the page.

 

@arunpatidar 

 

arunpatidar
Community Advisor
Community Advisor
March 20, 2023

Then remove

@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
Arun Patidar