Expandir minha barra de realizações na Comunidade.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.

SOLUCIONADO

Best practice to use sling models with WCMUse/WCMUsePojo class

Avatar

Level 7

Hi Team,

I would like to use sling models with WCMUse/WCMUsePojo class. For I have written the below code -

@Model(adaptables = Resource.class)
public class SampleSlingModel extends WCMUse {
    private static Logger LOG = LoggerFactory.getLogger(SampleSlingModel.class);
    @Inject
    private String title;

    @Override
    public void activate() throws Exception {
        LOG.info("SampleSlingModel.activate():Title:" + title);
    }

    public String getTitle() {
        return title;
    }

}

I'm able to get the value of title in component's sightly HTML using get method but the activate method is not invoked. If a class is extending WCMUse should call activate() but it is not. Can you please help me in this?

I tried to put @PostConstruct instead of @Override and activate method is called as sling model is treated it as just another method.

Is it best practice to proceed with this as the methods which are there in WCMUse/WCMUsePojo will not be available in the sling models?

Please suggest.

Thanks,

AryA.

1 Solução aceita

Avatar

Resposta correta de
Level 2

Hi,

I am not a model expert, but implementing wcmUse is different from Sling Models. You can use both from Sightly (not together), but according to [1] you don't need to have WcmUse and the activate() method at all. I've found [2] which covers the proper usage of wcmUse pojos with Sightly.

Jörg

 

[1] https://sling.apache.org/documentation/bundles/models.html

[2] http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-4/

Ver solução na publicação original

1 Resposta

Avatar

Resposta correta de
Level 2

Hi,

I am not a model expert, but implementing wcmUse is different from Sling Models. You can use both from Sightly (not together), but according to [1] you don't need to have WcmUse and the activate() method at all. I've found [2] which covers the proper usage of wcmUse pojos with Sightly.

Jörg

 

[1] https://sling.apache.org/documentation/bundles/models.html

[2] http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-4/