Squeakysand taglib NPE Calling getService
I am using the CQBlueprints archetype and following through the example implementation of simple tag library processing. The sample class provided is below. Seems pretty straight-forward. The OSGI bundles for the tablib and service are installed and Active. The GoodbyeWorldService bundle exports all its pacakges. The TLD generated is very simple. I can see that the setName method is called correctly from the provided JSP. Everything looks fine. HOWEVER ... as soon as the code hits the
GoodbyeWorldService service = getService(GoodbyeWorldService.class);
call an NPE occurs. :-
Caused by: java.lang.NullPointerException at com.mycompany.aem.archetypetest7.taglib.GoodbyeWorldTag.doTag(GoodbyeWorldTag.java:31)
Comment (3) below suggests that getService is a helper method inherited from the CqSimpleTagSupport class and I assumed would handle instantiation of GoodWorldService
Anyone else come across this, or has any suggestions ?
Kind regards
Fraser.
package com.mycompany.testproject.taglib; import com.cqblueprints.taglib.CqSimpleTagSupport; import com.squeakysand.jsp.tagext.annotations.JspTag; import com.squeakysand.jsp.tagext.annotations.JspTagAttribute; import com.mycompany.testproject.services.GoodbyeWorldService; import java.io.IOException; import javax.servlet.jsp.JspException; /** * Example JSP Custom Tag demonstrating three important concepts: * * 1. use of the SqueakySand annotations for auto-generating the Tag Library Descriptor (.tld) file * * 2. extending the CqSimpleTagSupport class from the CQ Blueprints library that provides many * useful methods to make writing JSP Custom Tags for the CQ platform easier for developers * * 3. accessing an OSGI service from within a JSP Custom Tag using one of the methods inherited * from the CqSimpleTagSupport class */ @JspTag public class GoodbyeWorldTag extends CqSimpleTagSupport { private String name; @Override public void doTag() throws JspException, IOException { GoodbyeWorldService service = getService(GoodbyeWorldService.class); String message = service.getMessage(name); getJspWriter().write(message); } public String getName() { return name; } @JspTagAttribute(required = true, rtexprvalue = true) public void setName(String name) { this.name = name; } }