Expand my Community achievements bar.

SOLVED

custom wcmcommand

Avatar

Level 5

I have a class RequestCommand implementing WCMCommand (com.day.cq.wcm.api.commands.WCMCommand).

When trying to implement the performCommand method, the return type (org.apache.sling.api.servlets.HtmlResponse) is deprecated and when I try to update it to the preferred type (org.apache.sling.servlets.post.HtmlResponse) shows the error "The return type is incompatible with WCMCommand.performCommand(WCMCommandContext, SlingHttpServletRequest, SlingHttpServletResponse, PageManager)"

I know I can probably use the deprecated class for now, but is there another way to do what I'm looking for potentially? 

Thanks

... public class RequestCommand implements WCMCommand { public String getCommandName() { return "requestPage"; } public HtmlResponse performCommand(WCMCommandContext commandContext, SlingHttpServletRequest request, SlingHttpServletResponse response, PageManager pageManager) { ...
1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

Well, you can use it as you like. But as you already found out, the product itself is using deprecated classes :-)

I would rather implement the servlets in your own namespace (/bin/myapp/doSomething). But binding servlets to a path (like /bin/wcmcommand) isn't the way servlets are supposed to work. In most (all?) cases you have a resource you want to modify. And in that case it makes sense to bind such a modification command as a selector to a specific resource type. See [1] as a good reference, plus it lists the pro's quite well.

Jörg

 

[1] http://stackoverflow.com/questions/22949317/cq5-5-accessing-a-referring-resource-in-a-osgi-servlet

View solution in original post

3 Replies

Avatar

Employee Advisor

Hi,

why do you want to implement the WCMCommand interface? When you want to implement server-side functionality you can call from your Javascript, you can use a simple servlet. No need to implement the WCMCommand interface.

Jörg

Avatar

Level 5

My main thinking was to try to keep as much code in this project's maven bundle as possible. I already have an interface built to manage these pages (marking them as trash/untrash, commenting, updating statuses). I was following the lead of the lock/unlock actions (/libs/cq/gui/components/authoring/clientlibs/editor/js/actions/lockMode.js).

Can you point me in the direction of what you're suggesting re:using a servlet?

Avatar

Correct answer by
Employee Advisor

Hi,

Well, you can use it as you like. But as you already found out, the product itself is using deprecated classes :-)

I would rather implement the servlets in your own namespace (/bin/myapp/doSomething). But binding servlets to a path (like /bin/wcmcommand) isn't the way servlets are supposed to work. In most (all?) cases you have a resource you want to modify. And in that case it makes sense to bind such a modification command as a selector to a specific resource type. See [1] as a good reference, plus it lists the pro's quite well.

Jörg

 

[1] http://stackoverflow.com/questions/22949317/cq5-5-accessing-a-referring-resource-in-a-osgi-servlet