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

org.ajaxanywhere.jsf.ZoneUIComponent Maven / Gradle / Ivy

Go to download

本项目主要弥补在使用mybatis3+springmvc+jquery easyui快速搭建web应用系统是遇到的框架不足. 主要工作包括: 1,扩展了ApplicationContextAware,通过单例注入spring容器,提供spring容器外的bean获取方法 2,扩展了apache shiro框架,统一了安全结构 3,扩展了mybatis3拦截器,在两个拦截器中自动完成分页注入,实现内存分页。 4,分页设计数据库方言 5,提供了一个easyuigrid的模型 6,提供了java泛型的jstl 7, xml工具包等一些小工具

The newest version!
package org.ajaxanywhere.jsf;

import org.ajaxanywhere.AAUtils;

import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.ValueBinding;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

@SuppressWarnings("deprecation")
public class ZoneUIComponent extends UIComponentBase {
	private static final String COMPONENT_FAMILY = "AjaxAnywhereFamily";

	public ZoneUIComponent() {
		setTransient(false);
	}

	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	public void encodeBegin(FacesContext context) throws IOException {
		if (context == null)
			throw new IllegalArgumentException("context is null");
		if (!isRendered())
			return;
		if (getId() == null)
			throw new IllegalArgumentException("name attribute is null");

		if (canSkipRendering(this, context))
			return;

		ResponseWriter writer = context.getResponseWriter();
		writer.write(AAUtils.getZoneStartDelimiter(getCompositeId()));

	}

	private String getCompositeId() {
		ValueBinding vb = getValueBinding("idSuffix");
		String compId = vb == null ? getId() : getId() + vb.getValue(getFacesContext());
		return compId;
	}

	public boolean getRendersChildren() {
		return true;
	}

	public void encodeChildren(FacesContext context) throws IOException {
		if (context == null)
			throw new IllegalArgumentException("context is null");
		if (canSkipRendering(this, context))
			return;

		renderChildren(context, this);
	}

	public void encodeEnd(FacesContext context) throws IOException {
		if (context == null)
			throw new IllegalArgumentException("context is null");
		if (!isRendered())
			return;
		if (canSkipRendering(this, context))
			return;

		ResponseWriter writer = context.getResponseWriter();
		writer.write(AAUtils.getZoneEndDelimiter(getCompositeId()));
	}

	@SuppressWarnings("rawtypes")
	private static void renderChildren(FacesContext facesContext, UIComponent component) throws IOException {
		if (component.getChildCount() > 0) {
			for (Iterator it = component.getChildren().iterator(); it.hasNext();) {
				UIComponent child = (UIComponent) it.next();
				renderComponent(facesContext, child);
			}
		}
	}

	private static void renderComponent(FacesContext facesContext, UIComponent child) throws IOException {

		if (!child.isRendered()) {
			return;
		}

		child.encodeBegin(facesContext);
		if (child.getRendersChildren()) {
			child.encodeChildren(facesContext);
		} else {
			renderChildren(facesContext, child);
		}
		child.encodeEnd(facesContext);
	}

	private static boolean canSkipRendering(UIComponent component, FacesContext context) {
		return noIncludedSubZones(component, context) && notInsideIncludedZone(component, context);
	}

	/**
	 * checks if this zones is surrently inside another included zone
	 */
	@SuppressWarnings("rawtypes")
	private static boolean notInsideIncludedZone(UIComponent component, FacesContext context) {
		Map requestMap = context.getExternalContext().getRequestMap();
		UIComponent parent = component.getParent();
		while (parent != null && !(parent instanceof UIViewRoot)) {
			if (isRefreshZone(parent, requestMap))
				return false;
			parent = parent.getParent();
		}
		return true;
	}

	/**
	 * checks if there are any sun-zones to include
	 */
	@SuppressWarnings("rawtypes")
	private static boolean noIncludedSubZones(UIComponent component, FacesContext context) {
		Map requestMap = context.getExternalContext().getRequestMap();
		Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
		if (!AAUtils.isAjaxRequest(requestParameterMap))
			return false;
		if (isRefreshZone(component, requestMap))
			return false;
		else {
			for (Iterator iterator = component.getChildren().iterator(); iterator.hasNext();) {
				UIComponent child = (UIComponent) iterator.next();
				if (!canSkipRendering(child, context))
					return false;
			}
			return true;
		}
	}

	@SuppressWarnings("rawtypes")
	private static boolean isRefreshZone(UIComponent component, Map requestMap) {
		if (component instanceof ZoneUIComponent == false)
			return false;

		ZoneUIComponent c = (ZoneUIComponent) component;
		for (Iterator it = AAUtils.getZonesToRefresh(requestMap).iterator(); it.hasNext();) {
			String zoneName = (String) it.next();
			if (c.getValueBinding("idSuffix") != null) {
				if (zoneName.startsWith(c.getId()))
					return true;
			} else {
				if (zoneName.equals(c.getId()))
					return true;
			}
		}
		return false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy