Best practice to use sling models with WCMUse/WCMUsePojo class | Community
Skip to main content
Dinu_Arya
Level 6
June 14, 2016
Solved

Best practice to use sling models with WCMUse/WCMUsePojo class

  • June 14, 2016
  • 1 reply
  • 3775 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by jörg_hoh1

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/

1 reply

jörg_hoh1
jörg_hoh1Accepted solution
Level 2
June 14, 2016

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/