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

org.ajax4jsf.taglib.ajax.AjaxSupportTag Maven / Gradle / Ivy

/**
 * 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.ajax4jsf.taglib.ajax;

import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentTag;

import org.ajax4jsf.ajax.UIAjaxSupport;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
import org.ajax4jsf.framework.taglib.UIComponentTagBase;
import org.ajax4jsf.framework.util.message.Messages;


/**
 * 
 * @author shura (latest modification by $Author: alexsmirnov $)
 * @version $Revision: 1.6 $ $Date: 2006/07/19 13:59:25 $
 *
 */
public class AjaxSupportTag extends UIComponentTagBase {

    static final String[] EVENT_HANDLER_ATTRIBUTES =
    {
        HTML.ondblclick_ATTRIBUTE,
        HTML.onmousedown_ATTRIBUTE,
        HTML.onmouseup_ATTRIBUTE,
        HTML.onmouseover_ATTRIBUTE,
        HTML.onmousemove_ATTRIBUTE,
        HTML.onmouseout_ATTRIBUTE,
        HTML.onkeypress_ATTRIBUTE,
        HTML.onkeydown_ATTRIBUTE,
        HTML.onkeyup_ATTRIBUTE,
        HTML.onclick_ATTRIBUTE,
        HTML.onchange_ATTRIBUTE,
        HTML.onblur_ATTRIBUTE,
        HTML.onfocus_ATTRIBUTE,
        HTML.onselect_ATTRIBUTE
    };
    
	public static final String AJAX_SUPPORT_FACET = "org.ajax4jsf.ajax.SUPPORT";
    /**
     * Id ( in form of findComponent method param ) of JSF component,
     * updated by this component ( parnt tag ) action.
     */
    private String reRender = null;
    
    /**
     * Generate script for given event ( onclick, onenter ... )
     */
    private String event = null;
    
    
    /**
     * Id of request status component.
     */
    private String status = null;
    
    /**
     * JavaScript function for call after request completed.
     */
    private String oncomplete = null ;
    
    private String action = null;
    private String actionListener = null;
    private String limitToList = null;
    private String disableDefault = null;
    private String value = null;
    private String immediate = null;
    private String ajaxSingle = null;
    



    /**
     * @param type The type to set.
     */
    public void setDisableDefault(String ajaxType)
    {
        this.disableDefault = ajaxType;
    }

    /**
     * @param reRender
     *            The targetId to set.
     */
    public void setReRender(String ajaxId) {
        this.reRender = ajaxId;
    }

    
    /**
     * @param event The event to set.
     */
    public void setEvent(String event)
    {
        this.event = event;
    }

    /**
     * @param oncomplete The oncomplete to set.
     */
    public void setOncomplete(String oncomplete)
    {
        this.oncomplete = oncomplete;
    }

    /**
     * @param status The status to set.
     */
    public void setStatus(String status)
    {
        this.status = status;
    }

    /**
     * @param limitToList The submitForm to set.
     */
    public void setLimitToList(String limitToList)
    {
        this.limitToList = limitToList;
    }

    /**
     * @param action The action to set.
     */
    public void setAction(String action)
    {
        this.action = action;
    }

    /**
     * @param actionListener The actionListener to set.
     */
    public void setActionListener(String actionListener)
    {
        this.actionListener = actionListener;
    }

    protected void setParentProperties(UIAjaxSupport uiComponent)  {

        //Find parent UIComponentTag
        UIComponentTag componentTag = null;
		try {
			componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
	        if (componentTag == null) {
	            throw new IllegalArgumentException(
	            		Messages.getMessage(Messages.NO_UI_COMPONENT_TAG_ANCESTOR_ERROR, "AjaxSupportTag"));
	        }

	        if (componentTag.getCreated()) {
	            //Component was just created, so we add the Listener
	            UIComponent component = componentTag.getComponentInstance();
	            uiComponent.setParentProperties(component);
	        }
		} catch (ClassCastException e) {
			// JSF 1.2 - tags have other parent.
		}

    } 

    /* (non-Javadoc)
     * @see javax.servlet.jsp.tagext.Tag#release()
     */
    public void release() {
        this.reRender = null;
        this.oncomplete = null;
        this.event = null;
        this.status =null;
        this.action = null;
        this.actionListener = null;
        this.limitToList = null;
        this.disableDefault = null;
        this.value = null;
        this.immediate=null;
        this.ajaxSingle = null;
        super.release();
    }

    /* (non-Javadoc)
     * @see javax.faces.webapp.UIComponentTag#getComponentType()
     */
    public String getComponentType()
    {
        
        return UIAjaxSupport.COMPONENT_TYPE;
    }

    /* (non-Javadoc)
     * @see javax.faces.webapp.UIComponentTag#getRendererType()
     */
    public String getRendererType()
    {
        
        return UIAjaxSupport.DEFAULT_RENDERER_TYPE;
    }

    /**
	 * @param value The value to set.
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @param immediate The immediate to set.
	 */
	public void setImmediate(String immediate) {
		this.immediate = immediate;
	}

	/**
	 * @param ajaxSingle The ajaxSingle to set.
	 */
	public void setAjaxSingle(String ajaxSingle) {
		this.ajaxSingle = ajaxSingle;
	}

	/* (non-Javadoc)
     * @see org.ajax4jsf.components.taglib.UIComponentTagBase#setProperties(javax.faces.component.UIComponent)
     */
    protected void setProperties(UIComponent component)
    {        
        super.setProperties(component);
        setStringProperty(component, "event", event);
        setReRenderProperty(component);
        setStringProperty(component, "status", status);
        setStringProperty(component, "oncomplete", oncomplete);
        setBooleanProperty(component, "disableDefault", disableDefault );
        setBooleanProperty(component, "limitToList", limitToList);
        setActionProperty(component, action);
        setActionListenerProperty(component, actionListener);
        setValueProperty(component,value);
        setBooleanProperty(component,"immediate",immediate);
        setBooleanProperty(component,"ajaxSingle",ajaxSingle);
        
        setParentProperties((UIAjaxSupport) component);
    }
    
    private void setReRenderProperty(UIComponent component) {
        if (reRender != null) {
            if (isValueReference(reRender)) {
            	setStringProperty(component, "reRender", reRender);
            } else {
                ((UIAjaxSupport) component).setReRender( AjaxRendererUtils.asSet(reRender));
            }
        }
    	
    }

	/* (non-Javadoc)
	 * @see javax.faces.webapp.UIComponentTag#getFacetName()
	 */
	protected String getFacetName() {
		// TODO Auto-generated method stub
		if (null != event) {
			return AJAX_SUPPORT_FACET + event;
		} else {
			return AJAX_SUPPORT_FACET;			
		}
	}
    
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy