com\esri\customtask\HyperlinkRenderer.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package com.esri.customtask; import java.util.logging.Level; import java.util.logging.Logger; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import org.w3c.dom.Element; import com.esri.adf.web.data.WebContext; import com.esri.adf.web.faces.component.MapControl; import com.esri.adf.web.faces.renderkit.xml.ajax.AJAXRenderer; import com.esri.adf.web.util.WebUtil; import com.esri.adf.web.util.XMLUtil; public class HyperlinkRenderer implements AJAXRenderer { /** the xml tag for postback processing */ public static String xmlTag = "hyperlink"; /** the name of the webContext attribute which stores the hyperlink string */ public static String attrName = "hyperlinkstr"; private static Logger logger = Logger.getLogger(HyperlinkRenderer.class.getName()); public Class getControlClass() { return MapControl.class; } public Object getOriginalState(UIComponent component) { return null; } public void renderAjaxResponse(FacesContext facesContext, UIComponent component, Object state, boolean iseventSource, Element parentElement) { try { WebContext ctx = WebUtil.getWebContext(component); if (ctx.getAttribute(attrName) == null) return; String linkstr = (String) ctx.getAttribute(attrName); // render xml document fragment for updating on client // set tag name for custom postback processing content Element rootElement = XMLUtil.createElement(xmlTag, null, parentElement); // add content to xml // e.g. <value>http://esri.com</value> XMLUtil.createElement("value", linkstr, rootElement); // set the webcontext attribute for hyperlink back to null ctx.setAttribute(attrName, null); } catch (Exception e) { if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, "Unable to encode xml.", e); } } } }