/*
 * Created on 04.08.2006
 */
package org.richfaces.component;

import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;

import org.ajax4jsf.component.UIAjaxCommandLink;
import org.ajax4jsf.renderkit.AjaxRendererUtils;

/**
 * @author igels
 */
abstract public class UIDialogClose extends UIDialogAction implements ActionPrefixHolder {
	public static final String COMPONENT_TYPE = UIAjaxCommandLink.COMPONENT_TYPE;
	public static final String COMPONENT_FAMILY = "javax.faces.Command";

    String prefix = null;
    boolean isNullPath = false;
    DialogCloseListenerImpl listener = new DialogCloseListenerImpl();
    
    public UIDialogClose() {}

	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	protected void setupReRender() {
		FacesContext context = getFacesContext();
		if(context.getMessages().hasNext()) {
			super.setupReRender();
		}
		AjaxRendererUtils.addRegionByName(context,this,this.getId());
	}
	
	public void setPrefix(String s) {
		prefix = s;
	}

	public String getPrefix() {
		return prefix;
	}
	
	public void setNullPath() {
		isNullPath = true;
	}

	public boolean isNullPath() {
		return isNullPath;
	}

	public void broadcast(FacesEvent event) throws AbortProcessingException {
		super.broadcast(event);
        if (event.isAppropriateListener(listener)) {
            event.processListener(listener);
        }
	}

}
