All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ajax4jsf.renderers.ajax.AjaxIncludeRenderer Maven / Gradle / Ivy

/**
 * Licensed under the Common Development and Distribution License,
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.sun.com/cddl/
 *   
 * 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.ajax4jsf.renderers.ajax;

import java.io.IOException;

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

import org.ajax4jsf.ajax.UIInclude;
import org.ajax4jsf.framework.renderer.RendererBase;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;

/**
 * @author [email protected] (latest modification by $Author: alexsmirnov $)
 * @version $Revision: 1.1 $ $Date: 2006/11/24 17:10:12 $
 * 
 */
public class AjaxIncludeRenderer extends RendererBase {

	private final String[] STYLE_ATTRIBUTES = new String[] { "style", "class" };

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.ajax4jsf.framework.renderer.RendererBase#getComponentClass()
	 */
	protected Class getComponentClass() {
		// TODO Auto-generated method stub
		return UIInclude.class;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.ajax4jsf.framework.renderer.RendererBase#doEncodeBegin(javax.faces.context.ResponseWriter,
	 *      javax.faces.context.FacesContext, javax.faces.component.UIComponent)
	 */
	protected void doEncodeBegin(ResponseWriter writer, FacesContext context,
			UIComponent component) throws IOException {
		UIInclude panel = (UIInclude) component;
		if (!UIInclude.LAYOUT_NONE.equals(panel.getLayout())) {
			writer.startElement(getTag(panel), panel);
			getUtils().encodeId(context, component);
			getUtils().encodePassThru(context, component);
			getUtils().encodeAttributesFromArray(context, component,
					STYLE_ATTRIBUTES);

		}
	}

	/**
	 * @param panel
	 * @return
	 */
	private String getTag(UIInclude panel) {
		// TODO Auto-generated method stub
		return UIInclude.LAYOUT_BLOCK.equals(panel.getLayout()) ? HTML.DIV_ELEM
				: HTML.SPAN_ELEM;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.ajax4jsf.framework.renderer.RendererBase#doEncodeEnd(javax.faces.context.ResponseWriter,
	 *      javax.faces.context.FacesContext, javax.faces.component.UIComponent)
	 */
	protected void doEncodeEnd(ResponseWriter writer, FacesContext context,
			UIComponent component) throws IOException {
		UIInclude panel = (UIInclude) component;
		if (!UIInclude.LAYOUT_NONE.equals(panel.getLayout())) {
			writer.endElement(getTag(panel));

		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy