We are using dxa-2.2.5 Java and we are using GraphQlLinkresolver. We want to get url of detail page of Component TCM, how can we achieve it?

On Model class I have tried something like this:

public String getUrl(String localizationId){
    LinkResolver linkResolver = new GraphQLLinkResolver();
    return linkResolver.resolveLink(TcmUtils.buildTcmUri(localizationId,getId()),localizationId);

I am getting this error:

13:53:39.720 [http-nio-8080-exec-1] ERROR   o.a.c.c.C.[.[localhost].[/].[jsp] - Servlet.service() for servlet
[jsp] threw exception java.lang.NullPointerException: null at
com.sdl.dxa.tridion.linking.GraphQLLinkResolver.resolveComponent(GraphQLLinkResolver.java:28) at
com.sdl.webapp.tridion.linking.AbstractLinkResolver._resolveLink(AbstractLinkResolver.java:69) at
com.sdl.webapp.tridion.linking.AbstractLinkResolver.resolveLink(AbstractLinkResolver.java:35) at

Can someone please advise on this, what is wrong here or suggest me how can I get page url of Component?


I can only give you the answer in .NET (because I haven't worked with DXA Java still), but I'm certain that the same or a very similar approach should be used.

The bigger mistake is that the resolveLink() method expects the ID of the Component it's supposed to resolve. In your code, you are giving it the Publication ID.

One other thing which should be avoided is directly newing the GraphQLLinkResolver yourself. That way you hardcode the type instead of relying on DI. In .NET you have all the providers available to you from the SiteConfiguration class. Now I don't know whether it's called the same in Java, but I expect something similar to exist.

See the attached screenshot for .NET: enter image description here

  • Hi @Atila, Thanks for you suggestion, problem in my code was i was newing GraphQlLinkResolver, instead of that I Updated that line with LinkResolver linkResolver = BeanUtil.getBean(LinkResolver.class); – Neetesh Narvaria Oct 22 '20 at 10:07
  • so now application is taking linkresolver from spring context, Thanks a lot :) . – Neetesh Narvaria Oct 22 '20 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.