Expand my Community achievements bar.

SOLVED

Sightly / WCMUse error.

Avatar

Level 1

Hi, I'm trying to create a WCMUse java object at the component level to use with sightly, and I keep getting the following error:

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: No use provider could resolve identifier: AEMUser

The idea is to wrap the jackrabbit user class for use by sightly, my company does a lot with security groups and prefer to do things on the code level vs the author targeting level (our authors don't understand targeting)

Anyway, here is the class that wraps the jackrabbit User class:

package apps.AEMUPGRADE.components.aemUser; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.api.security.user.Group; import com.adobe.cq.sightly.WCMUse; public class AEMUser extends WCMUse{ private String username; private User user; public AEMUser(String username){ this.username = username; } @Override public void activate() throws Exception { username = get("username", String.class); user = getResource().adaptTo(User.class); } public User getUser(){ return user; } public String getUsername(){ return username; } public java.util.Iterator<Group> getUserGroups(){ try{ if(user!=null){ return user.memberOf(); } }catch(javax.jcr.RepositoryException jre){ //Hold off for now } return null; } }

I will likely move this into a bundle but just wanted to get it working first.
Here is my sightly code:

 

<div class="${properties.cssClass}"> Hello, ${request.remoteUser} </div> <p>You belong to the following groups</p> <ul data-sly-use.aemUser="AEMUser"> <li>${user.username}</li> <li> <ul data-sly-list.child="${user.userGroups}"> <li>${childList.index}:${child.iD}</li> </ul> </li> </ul>

And here are the paths:
/apps/AEMUPGRADE/components/aemUser/aemUser.html
/apps/AEMUPGRADE/components/aemUser/AEMUser.java
 

I followed all the examples to make this, not sure what I did wrong, I keep going over and over it but it doesn't seem to want to register AEMUser as a sightly object.

Am I missing something?

1 Accepted Solution

Avatar

Correct answer by
Level 8

You issue is the constructor. Either remove your constructor, or add a no arg constructor that just calls super. 

View solution in original post

4 Replies

Avatar

Correct answer by
Level 8

You issue is the constructor. Either remove your constructor, or add a no arg constructor that just calls super. 

Avatar

Level 1

Hi, it looks like a java problem with upper case package names. Can you try convert this path /apps/AEMUPGRADE/components/aemUser/  all to lower case and then change 

  1. package apps.AEMUPGRADE.components.aemUser; to
  2. package apps.aemupgrade.components.aemuser;

that should do the trick

Avatar

Level 1

Hm, I removed the constructor and still get the  No use provider could resolve identifier exception...

Same thing when putting in a default with super();

 

Any other thoughts? I even tried giving it the fully qualified name.

Is there maybe a special nodetype I need for it to register?

Avatar

Level 1

As a follow up, I got this to work by killing the generated java class files in the /var/classes/<id> folder

There were old versions of my java class there which were conflicting with the correct version, from when I thought my package naming was wrong.

Thanks for the help, orotas has the correct solution.