Skip to main content
Level 8
Oct 16, 2015 2:27 AM UTC
Solved

Invoke WCMUse Class from Servlet

Is it possible to use a class which extends WCMUse from inside of a servlet?  If so, are there any examples available?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Adobe Employee
Oct 16, 2015 2:27 AM UTC

No..., at least this is not the intended way of using WCMUse...

4 replies

Feike_Visser1
Adobe Employee
Adobe Employee
Oct 16, 2015 2:27 AM UTC

I would look towards Sling Models in that case. http://sling.apache.org/documentation/bundles/models.html

This can be used from Sightly as well as Java-code. From Sightly it must be adaptable from Request or Resource.

 

Something like this..., 

@Model(adaptables = SlingHttpServletRequest.class)

public class HeaderComponent {

    private SlingHttpServletRequest request;

public HeaderComponent(SlingHttpServletRequest request) {

this.request = request;

}

@PostConstruct

protected void init(){

// do your stuff...

}

}

Translate
leeaslingAuthor
Level 8
Oct 16, 2015 2:27 AM UTC

Feike Visser wrote...

What is the use-case you have in mind?

 

I have a class that utilizes WCMUse and builds out a list of news articles using Sightly.  I would also like to be able to utilize the same code in my servlet to avoid duplicate code (I have a requirement where one area needs AJAX to display data and the other does not).  I think I can achieve what I need to do pretty easily without invoking the WCMUse class and just separating out the logic into a different package/class within my OSGI bundle - I was just curious if this functionality existed.

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
Oct 16, 2015 2:27 AM UTC

What is the use-case you have in mind?

Translate
Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
Oct 16, 2015 2:27 AM UTC

No..., at least this is not the intended way of using WCMUse...

Translate