Expand my Community achievements bar.

SOLVED

Java Use-API: No use provider could resolve identifier

Avatar

Former Community Member

Hi everybody,

I'm experimenting with the new Java Use-API [1] but I'm having trouble getting it to work.

  1. I have a component here: /apps/abc/components/modular/C03-topbanner/
  2. Following the instructions, I put my .java file here: /apps/abc/components/modular/C03-topbanner/C03_topbanner.java
  3. The package name in the java file is: apps.abc.components.modular.c03_topbanner (replacing the - with _ as described)
  4. The class name is C03_topbanner
  5. Within my sightly file (/apps/abc/components/modular/C03-topbanner/C03-topbanner.html) I'm calling it like so: data-sly-use.topbanner="c03_topbanner"
  6. This gets me the extension: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: No use provider could resolve identifier: c03_topbanner
  7. I've tried a few variation with file/package/class names but it never seems to work... The way I understand it from the docs is that just the package name has to be the same as the use class

Any ideas what I could be missing?

[1] http://docs.adobe.com/docs/en/aem/6-0/develop/sightly/use-api-in-java.html

1 Accepted Solution

Avatar

Correct answer by
Employee

The data-sly-use attribute uses the class name for java files, which are case sensitive. Looks like you used 

data-sly-use.topbanner="c03_topbanner"

Rather than

data-sly-use.topbanner="C03_topbanner"

Hopefully that fixes your error.

View solution in original post

10 Replies

Avatar

Correct answer by
Employee

The data-sly-use attribute uses the class name for java files, which are case sensitive. Looks like you used 

data-sly-use.topbanner="c03_topbanner"

Rather than

data-sly-use.topbanner="C03_topbanner"

Hopefully that fixes your error.

Avatar

Level 8

Does you class implement the WCMUse interface, and does it have an activate method? I have seen where that was an issue that generated the same error. 

Avatar

Former Community Member

Yes. Here's my dummy code so far:

package apps.abc.components.modular.c03_topbanner; import com.adobe.cq.sightly.WCMUse; import com.day.cq.wcm.api.components.DropTarget.CSS_CLASS_PREFIX; public class C03_topbanner extends WCMUse { private String cssClass; @Override public void activate() throws Exception { cssClass = DropTarget.CSS_CLASS_PREFIX; } public String getCssClass() { return cssClass; } }

Avatar

Former Community Member

I got it to work now. I'm actually not sure what solved it in the end because I was pretty sure I had tested all these combinations. I changed the package and class name to "C03_topbanner". 

Avatar

Level 3

I am having a similar issue was wondering if someone could help.

    Component is located in /apps/global-web/components/content/relatedlinks/
    .java located in /apps/global-web/components/content/relatedlinks/MFPF.java (which extends WCMUse and I Override activate() )
    package name is apps.global_web.components.content.relatedlinks
    class name is MFPF
    sightly file (/apps/global-web/components/content/relatedlinks/relatedlinks.html) calls the java class as such: data-sly-use.mfpf="MFPF"

I actually shortened the class name down to MFPF in case there was some sort of weird length limit and have tried multiple variations.

Any thoughts?

Avatar

Former Community Member

Have you tried commenting out everything to narrow it down? I've had the same error message one time and it turned out there was just a java error that never showed up anywhere..

Avatar

Employee

Do you see your class to be compiled in /var/classes?

Otherwise I would try to move it to an OSGi-bundle to see if that works, then you know the Use-class is fine.

Avatar

Level 3

Thanks for the responses guys.  I have stripped it down to bare bones to try and get it to compile so this is what I have in the class currently:

package apps.global_web.components.content.relatedlinks

import com.adobe.cq.sightly.WCMUse;

public class MFPF extends WCMUse {
    private String testVal;

    @Override
    public void activate() throws Exception {
        //testVal = "I can write a class that actually works!";
    }

    /*public String getTestVal() {
        return testVal;
    }*/
}

I just checked var/classes and no I do not see anything in there.  Would it be in/near the root or would it setup a similar folder structure to the one that is existing in there (in this class's case apps/global_web/etc...) ?

Avatar

Level 3

OK, so we found the error before dropping it over in an OSGi bundle, no semi-colon on the package.blush

Avatar

Employee

Nice one! :-) Great that this is now resolved.