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

org.ajax4jsf.framework.ajax.AjaxListenerHelper 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 java.io.Serializable;

import javax.faces.component.StateHolder;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

/**
 * Helper class to keep reference to listener binded as EL-expression.
 * @author shura
 *
 */
public class AjaxListenerHelper implements AjaxListener,StateHolder {
	
	
	private ValueBinding _binding;
	
	
	private boolean _transient = false;

	
	/**
	 * 
	 */
	public AjaxListenerHelper() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param binding
	 */
	public AjaxListenerHelper(ValueBinding binding) {
		super();
		if (null == binding) {
			throw new IllegalArgumentException("Binding expression for AjaxListener helper must be not null");
		}
		_binding = binding;
	}

	private AjaxListener getHandler(FacesContext context) {
		return (AjaxListener) _binding.getValue(context);
	}

	/* (non-Javadoc)
	 * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
	 */
	public void restoreState(FacesContext context, Object state) {
		State helperState = (State) state;
		_binding = (ValueBinding) UIComponentBase.restoreAttachedState(context,helperState.binding);
	}

	/* (non-Javadoc)
	 * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
	 */
	public Object saveState(FacesContext context) {
		State helperState = new State();
		helperState.binding = UIComponentBase.saveAttachedState(context,_binding);
		return helperState;
	}

	/**
	 * @return Returns the transient.
	 */
	public boolean isTransient() {
		return _transient;
	}

	/**
	 * @param transient1 The transient to set.
	 */
	public void setTransient(boolean transient1) {
		_transient = transient1;
	}
	
	/**
	 * @author shura
	 *
	 */
	private static class State implements Serializable {
		
		
		private Object binding;
		

	}

	public void processAjax(AjaxEvent event) {
		FacesContext context = FacesContext.getCurrentInstance();
		AjaxListener handler = getHandler(context);
		handler.processAjax(event);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy