Question
Extend Teaser Component using Sling Model Delegate Pattern
Hi,
I have been trying to extend Teaser component behaviour using Sling Delegate Pattern. I want to overwrite the linkUrl property behaviour but it is not working as expected. The link on the image is always the one which is configured on the component but I expect it to be overwritten by the static link from the below overwritten method.
import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.wcm.core.components.models.ListItem;
import com.adobe.cq.wcm.core.components.models.Teaser;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;
import java.util.List;
@Model(
adaptables = SlingHttpServletRequest.class,
adapters = {Teaser.class, ComponentExporter.class},
resourceType = "myproject/components/content/teaser",
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class CustomTeaserImpl implements Teaser {
@Self
@Via(type = ResourceSuperType.class)
private Teaser teaser;
@Override
public String getLinkURL() {
return "/content/subrato/foo";
}
/**
* Checks if the teaser has Call-to-Action elements
*
* @return {@code true} if teaser has CTAs, {@code false} otherwise
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public boolean isActionsEnabled() {
return this.teaser.isActionsEnabled();
}
/**
* Returns the list of Call-to-Action elements
*
* @return the list of CTAs
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public List<ListItem> getActions() {
return this.teaser.getActions();
}
/**
* Returns the image resource for this teaser.
*
* @return the image resource for this teaser or {@code null}
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public Resource getImageResource() {
return this.teaser.getImageResource();
}
/**
* Checks if the link on the image is hidden.
*
* @return {@code true} if link is hidden on the image, {@code false} otherwise
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public boolean isImageLinkHidden() {
return this.teaser.isImageLinkHidden();
}
/**
* Returns this teaser's pretitle, if one was defined.
*
* @return the teaser's pretitle or {@code null}
*
* @since com.adobe.cq.wcm.core.components.models 12.12.0
*/
@Override
public String getPretitle() {
return this.teaser.getPretitle();
}
/**
* Returns this teaser's title, if one was defined.
*
* @return the teaser's title or {@code null}
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public String getTitle() {
return this.teaser.getTitle();
}
/**
* Checks if the link on the title is hidden.
*
* @return {@code true} if link is hidden on the title, {@code false} otherwise
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public boolean isTitleLinkHidden() {
return this.teaser.isTitleLinkHidden();
}
/**
* Returns this teaser's description, if one was defined.
*
* @return the teaser's description or {@code null}
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public String getDescription() {
return this.teaser.getDescription();
}
/**
* Returns the HTML element type (h1-h6) used for the title.
*
* @return the element type
*
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public String getTitleType() {
return this.teaser.getTitleType();
}
/**
* @since com.adobe.cq.wcm.core.components.models 12.4.0
*/
@Override
public String getExportedType() {
return this.teaser.getExportedType();
}
}