package org.example.handlers; import com.sun.jsftemplating.annotation.Handler; import com.sun.jsftemplating.annotation.HandlerInput; import com.sun.jsftemplating.annotation.HandlerOutput; import com.sun.jsftemplating.component.ComponentUtil; import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext; import com.sun.jsftemplating.layout.event.CreateChildEvent; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; /** *

This class is written to demonstrate how to write a * Handler.

*/ public class DynamicColumnHandlers { /** *

This handler creates a hyprlink using the event object * information.

* * @param context The HandlerContext. */ @Handler(id="Test.createHyperLink") public static UIComponent calculateResponse(HandlerContext context) { if (!context.getEventType().equals(CreateChildEvent.EVENT_TYPE)) { throw new IllegalArgumentException( "This event only works for createChild events!"); } CreateChildEvent event = (CreateChildEvent) context.getEventObject(); FacesContext ctx = context.getFacesContext(); UIComponent comp = ctx.getApplication(). createComponent("com.sun.webui.jsf.Hyperlink"); String url = "http://www.google.com/search?q=" + event.getData(); if (ComponentUtil.isValueReference(url)) { comp.setValueExpression("url", ctx.getApplication().getExpressionFactory(). createValueExpression( ctx.getELContext(), url, String.class)); } else { comp.getAttributes().put("url", url); } comp.getAttributes().put("value", "Click Me!"); return comp; } }