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

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

Go to download

Ajax4jsf is an open source extension to the JavaServer Faces standard that adds AJAX capability to JSF applications without requiring the writing of any JavaScript.

The newest version!
/**
 * 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.component.html.HtmlCommandButton;

import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
import org.ajax4jsf.framework.taglib.HtmlComponentTagBase;
import org.ajax4jsf.renderers.ajax.AjaxCommandButtonRenderer;


/**
 * @author shura
 * Create HtmlCommandButton component with custom Ajax renderer.
 * 
 */
public class AjaxCommandButtonTag extends HtmlComponentTagBase {

    private static final String AJAX_INPUT_TYPE = "input";
	// HTML input attributes relevant for command-button
    private String _accesskey;
    private String _alt;
    private String _disabled;
    private String _onblur;
    private String _onchange;
    private String _onfocus;
    private String _onselect;
    private String _size;
    private String _tabindex;
    private String _type;

    // UICommand attributes
    private String _action;
    private String _immediate;
    private String _actionListener;

    // HtmlCommandButton attributes
    private String _image;

	
	/**
     * 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 ;
    
    /**
     * If "true" , on client side update only defined by targetId areas.
     */
    private String limitToList = null;
    /**
     * Type of input field. 
     */
    private String ajaxType = AJAX_INPUT_TYPE;

    private String ajaxSingle = null;

    /**
	 * @param accesskey The accesskey to set.
	 */
	public void setAccesskey(String accesskey) {
		_accesskey = accesskey;
	}

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

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

	/**
	 * @param alt The alt to set.
	 */
	public void setAlt(String alt) {
		_alt = alt;
	}

	/**
	 * @param disabled The disabled to set.
	 */
	public void setDisabled(String disabled) {
		_disabled = disabled;
	}

	/**
	 * @param image The image to set.
	 */
	public void setImage(String image) {
		_image = image;
	}

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

	/**
	 * @param onblur The onblur to set.
	 */
	public void setOnblur(String onblur) {
		_onblur = onblur;
	}

	/**
	 * @param onchange The onchange to set.
	 */
	public void setOnchange(String onchange) {
		_onchange = onchange;
	}

	/**
	 * @param onfocus The onfocus to set.
	 */
	public void setOnfocus(String onfocus) {
		_onfocus = onfocus;
	}

	/**
	 * @param onselect The onselect to set.
	 */
	public void setOnselect(String onselect) {
		_onselect = onselect;
	}

	/**
	 * @param size The size to set.
	 */
	public void setSize(String size) {
		_size = size;
	}

	/**
	 * @param tabindex The tabindex to set.
	 */
	public void setTabindex(String tabindex) {
		_tabindex = tabindex;
	}

	/**
	 * @param type The type to set.
	 */
	public void setType(String type) {
		_type = type;
	}

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

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

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

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

    /**
     * @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 targetId The targetId to set.
     */
    public void setReRender(String targetId)
    {
        this.reRender = targetId;
    }

    /* (non-Javadoc)
     * @see org.ajax4jsf.components.taglib.html.HtmlCommandButtonTagBase#setProperties(javax.faces.component.UIComponent)
     */
    protected void setProperties(UIComponent component)
    {
        // TODO Auto-generated method stub
        super.setProperties(component);
        // Setup button properties
        setStringProperty(component, HTML.accesskey_ATTRIBUTE, _accesskey);
        setStringProperty(component, HTML.alt_ATTRIBUTE, _alt);
        setBooleanProperty(component, HTML.DISABLED_ATTR, _disabled);
        setStringProperty(component, HTML.onblur_ATTRIBUTE, _onblur);
        setStringProperty(component, HTML.onchange_ATTRIBUTE, _onchange);
        setStringProperty(component, HTML.onfocus_ATTRIBUTE, _onfocus);
        setStringProperty(component, HTML.onselect_ATTRIBUTE, _onselect);
        setStringProperty(component, HTML.size_ATTRIBUTE, _size);
        setStringProperty(component, HTML.tabindex_ATTRIBUTE, _tabindex);
        setStringProperty(component, HTML.TYPE_ATTR, _type);
        setActionProperty(component, _action);
        setActionListenerProperty(component, _actionListener);
        setBooleanProperty(component, "immediate", _immediate);
        setStringProperty(component, "image", _image);
        
//        setStringProperty(component, "event", event);
        setStringProperty(component, AjaxRendererUtils.AJAX_REGIONS_ATTRIBUTE, reRender);
        setStringProperty(component, AjaxRendererUtils.STATUS_ATTR_NAME, status);
        setStringProperty(component, AjaxRendererUtils.ONCOMPLETE_ATTR_NAME, oncomplete);
        setStringProperty(component, "ajaxType", ajaxType );
        setBooleanProperty(component,"ajaxSingle",ajaxSingle );
        setBooleanProperty(component, AjaxRendererUtils.LIMITTOLIST_ATTR_NAME, limitToList);
    }

    /* (non-Javadoc)
     * @see org.ajax4jsf.components.taglib.html.HtmlCommandButtonTagBase#release()
     */
    public void release()
    {
        // TODO Auto-generated method stub
        super.release();
        // Common button attributes
        _accesskey=null;
        _alt=null;
        _disabled=null;
        _onblur=null;
        _onchange=null;
        _onfocus=null;
        _onselect=null;
        _size=null;
        _tabindex=null;
        _type=null;
        _action=null;
        _immediate=null;
        _actionListener=null;
        _image=null;
        // AJAX button attributes
        reRender=null;
        event = null;
        ajaxType = AJAX_INPUT_TYPE;
        limitToList = null;
        oncomplete = null;
        status = null;
        ajaxSingle = null;
    }

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

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


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy