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

org.ajax4jsf.taglib.ajax.ActionParamTag 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.application.Application;
import javax.faces.component.ActionSource;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.webapp.UIComponentTag;

import org.ajax4jsf.ajax.UIActionParameter;
import org.ajax4jsf.framework.taglib.UIComponentTagBase;
import org.ajax4jsf.framework.util.message.Messages;


/**
 * @author shura (latest modification by $Author: slava_kabanovich $)
 * @version $Revision: 1.2 $ $Date: 2006/07/12 14:59:34 $
 *
 */
public class ActionParamTag extends UIComponentTagBase
{

    /* (non-Javadoc)
     * @see javax.faces.webapp.UIComponentTag#getComponentType()
     */
    public String getComponentType()
    {
        return "org.ajax4jsf.components.ActionParameter";
    }

    /* (non-Javadoc)
     * @see javax.faces.webapp.UIComponentTag#getRendererType()
     */
    public String getRendererType()
    {
        return null;
    }
    // UIComponent attributes --> already implemented in UIComponentTagBase

    // UIParameter attributes
    // value already implemented in UIComponentTagBase
    private String _name;
    private String _assignTo;
    private String _converter;
    private String _noEscape;

    protected void setProperties(UIComponent component)
    {
        super.setProperties(component);        
        setStringProperty(component, "name", _name);
        setBooleanProperty(component, "noEscape", _noEscape);

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

        if (componentTag.getCreated())
        {
            //Component was just created, so we add the Listener
            UIComponent parentComponent = componentTag.getComponentInstance();
            if (parentComponent instanceof ActionSource)
            {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                Application application = facesContext.getApplication();
                if (_assignTo != null) {
                    if (!UIComponentTag.isValueReference(_assignTo)) throw new IllegalArgumentException(Messages.getMessage(Messages.NO_VALUE_REFERENCE_ERROR_2, _assignTo));
                    UIActionParameter al = (UIActionParameter)component;
                    al.setAssignToBinding(application.createValueBinding(_assignTo));
                if (_converter != null)
                {
                    Converter converter = application.createConverter(_converter);
                    al.setConverter(converter);
                }
                ((ActionSource)parentComponent).addActionListener(al);
                }
            }
        }

    }

    public void setName(String name)
    {
        _name = name;
    }

    /**
     * @param converter The converter to set.
     */
    public void setConverter(String converter)
    {
        this._converter = converter;
    }

    /**
     * @param noEscape The noEscape to set.
     */
    public void setNoEscape(String noEscape)
    {
        this._noEscape = noEscape;
    }

    /**
     * @param property The property to set.
     */
    public void setAssignTo(String property)
    {
        this._assignTo = property;
    }

    /* (non-Javadoc)
     * @see org.apache.myfaces.taglib.UIComponentTagBase#release()
     */
    public void release()
    {
        _name = null;
        _assignTo = null;
        _converter = null;
        _noEscape = null;
        super.release();
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy