Last active
December 25, 2015 16:19
-
-
Save joemaffia/7004438 to your computer and use it in GitHub Desktop.
Adobe CQ JSP Custom Tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company.cq.taglib; | |
import com.cqblueprints.taglib.CqSimpleTagSupport; | |
import com.squeakysand.jsp.tagext.annotations.JspTag; | |
import com.squeakysand.jsp.tagext.annotations.JspTagAttribute; | |
import com.englishtown.cq.b2c.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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment