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

org.ajax4jsf.framework.ajax.EventValueBinding 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!
/**
 * Licensed under the Common Development and Distribution License,
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.sun.com/cddl/
 *   
 * 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.framework.ajax;

import javax.faces.component.StateHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.PropertyNotFoundException;
import javax.faces.el.ValueBinding;

import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.util.message.Messages;


/**
 * Inner class for build event string for parent component.
 * @author shura (latest modification by $Author: alexsmirnov $)
 * @version $Revision: 1.5 $ $Date: 2007/01/16 17:53:18 $
 * Disadvantages - not rebuild event string setted as EL expression.
 * TODO - save expressions for build event string at render phase.
 */
public class EventValueBinding extends ValueBinding implements StateHolder {
    
    /**
     * 
     */
    private static final long serialVersionUID = -6583167387542332290L;
    private String _componentId;
    
    
    /**
     * current update component. transient since saved state as component. 
     */
    transient private AjaxSupport _component = null;
    
    /**
     * Default constructor for restoreState.
     */
    public EventValueBinding() {
    	
    }

    /**
     * Constructor for build from AjaxComponent.
     * @param update
     */
    public EventValueBinding(AjaxSupport update)
    {
        _component = update;
//        _componentId = string;
    }

    /* (non-Javadoc)
     * @see javax.faces.el.ValueBinding#getType(javax.faces.context.FacesContext)
     */
    public Class getType(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
    {
        
        return String.class;
    }

    /* (non-Javadoc)
     * @see javax.faces.el.ValueBinding#getValue(javax.faces.context.FacesContext)
     */
    public Object getValue(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
    {
    	return getComponent(facesContext).getEventString();
    }
    
    private AjaxSupport getComponent(FacesContext facesContext) throws EvaluationException {

        if (_component == null)
        {
             UIComponent uiComponent = facesContext.getViewRoot().findComponent(_componentId);
            if (null != uiComponent && uiComponent instanceof AjaxComponent)
            {
                _component = (AjaxSupport) uiComponent;                    
            } else {
                throw new EvaluationException(Messages.getMessage(Messages.COMPONENT_NOT_FOUND, _componentId));
            }
            
        }

        return _component;
    }

    /**
	 * @param component the component to set
	 */
	public void setComponent(AjaxSupport component) {
		_component = component;
	}

	/* (non-Javadoc)
     * @see javax.faces.el.ValueBinding#isReadOnly(javax.faces.context.FacesContext)
     */
    public boolean isReadOnly(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
    {
        // TODO Auto-generated method stub
        return true;
    }

    /* (non-Javadoc)
     * @see javax.faces.el.ValueBinding#setValue(javax.faces.context.FacesContext, java.lang.Object)
     */
    public void setValue(FacesContext facesContext, Object value) throws EvaluationException, PropertyNotFoundException
    {
        throw new EvaluationException(Messages.getMessage(Messages.EVENT_IS_READ_ONLY));
        
    }

    /* (non-Javadoc)
     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
     */
    public Object saveState(FacesContext context)
    {
    	if(null == _component){
    		return _componentId;
    	} else {
    		return AjaxRendererUtils.getAbsoluteId((UIComponent) _component);
    	}
    }

    /* (non-Javadoc)
     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
     */
    public void restoreState(FacesContext context, Object state)
    {
        // TODO Auto-generated method stub
        _componentId = (String)state;
    }

    /* (non-Javadoc)
     * @see javax.faces.component.StateHolder#isTransient()
     */
    public boolean isTransient()
    {
        // TODO Auto-generated method stub
        return false;
    }

    /* (non-Javadoc)
     * @see javax.faces.component.StateHolder#setTransient(boolean)
     */
    public void setTransient(boolean newTransientValue)
    {
        // TODO Auto-generated method stub
        
    }

	/* (non-Javadoc)
	 * @see javax.faces.el.ValueBinding#getExpressionString()
	 */
	public String getExpressionString() {
//		FacesContext context = FacesContext.getCurrentInstance();
//		UIComponent component = (UIComponent) getComponent(context);
//		return "#{ajaxSupport["+component.getClientId(context)+"]}";
		return null;
	}
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy