Package org.apache.myfaces.custom.graphicimageajax

Source Code of org.apache.myfaces.custom.graphicimageajax.GraphicImageAjaxRenderer

/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.myfaces.custom.graphicimageajax;

import java.io.IOException;

import javax.faces.application.ViewHandler;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

import org.apache.myfaces.renderkit.RendererUtils;
import org.apache.myfaces.renderkit.html.HTML;
import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
import org.apache.myfaces.renderkit.html.ext.HtmlImageRenderer;

/**
* @author Sylvain Vieujot
* @version $Revision: 292080 $ $Date: 2005-05-23 19:39:37 +0200 (Mon, 23 May 2005) $
*/
public class GraphicImageAjaxRenderer extends HtmlImageRenderer
{
  public static final String RENDERER_TYPE = "org.apache.myfaces.GraphicImageAjaxRenderer";
 
    public void encodeEnd(FacesContext context, UIComponent component) throws IOException
    {
        RendererUtils.checkParamValidity(context, component, GraphicImageAjax.class);
       
        GraphicImageAjax graphicImageAjax = (GraphicImageAjax) component;
        ResponseWriter out = context.getResponseWriter();

        String clientId = graphicImageAjax.getClientId(context);
       
        out.startElement(HTML.IMG_ELEM, graphicImageAjax);
        out.writeAttribute(HTML.ID_ATTR, clientId, null);
        HtmlRendererUtils.renderHTMLAttributes(out, graphicImageAjax, HTML.IMG_PASSTHROUGH_ATTRIBUTES);

        out.endElement(HTML.IMG_ELEM);

        String viewId = context.getViewRoot().getViewId();
        ViewHandler viewHandler = context.getApplication().getViewHandler();
        String actionURL = viewHandler.getActionURL(context, viewId);

        out.startElement(HTML.SCRIPT_ELEM, null);
        out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
        out.writeText("document.getElementById('"+clientId+"').src='",null);
        out.writeText(context.getExternalContext().encodeActionURL(actionURL+"?affectedGraphicImageComponent="+clientId),null);
        out.writeText("&jsf_tree_64='+encodeURIComponent(document.getElementById('jsf_tree_64').value)+'&jsf_state_64='+encodeURIComponent(document.getElementById('jsf_state_64').value)+'&jsf_viewid='+encodeURIComponent(document.getElementById('jsf_viewid').value);", null);
        out.endElement(HTML.SCRIPT_ELEM);
    }

    public void decode(FacesContext facesContext, UIComponent component)
    {
        super.decode(facesContext, component);
    }
}
TOP

Related Classes of org.apache.myfaces.custom.graphicimageajax.GraphicImageAjaxRenderer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.