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

org.ajax4jsf.ajax.UIAjaxForm 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.ajax;

import java.util.Iterator;

import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;

import org.ajax4jsf.framework.ajax.AjaxComponent;
import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.ajax4jsf.framework.ajax.AjaxListener;
import org.ajax4jsf.framework.ajax.AjaxSource;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;


/**
 * Quite different from default HtmlForm - process child components
 * not only for submitted form, but if submitted parent AjaxContainer
 * @author shura (latest modification by $Author: alexsmirnov $)
 * @version $Revision: 1.5 $ $Date: 2006/11/28 17:33:31 $
 *
 */
public abstract class UIAjaxForm extends UIForm implements AjaxComponent, AjaxSource 
{
    public static final String COMPONENT_TYPE = "org.ajax4jsf.Form";

    /* (non-Javadoc)
     * @see javax.faces.component.UIComponent#processDecodes(javax.faces.context.FacesContext)
     */
    public void processDecodes(javax.faces.context.FacesContext context)
    {
        if (context == null) throw new NullPointerException("context");
        decode(context);
        if (mustProcessed(context))
        {
            for (Iterator it = getFacetsAndChildren(); it.hasNext();)
            {
                UIComponent childOrFacet = (UIComponent) it.next();
                childOrFacet.processDecodes(context);
            }
        }
    }

    
    /* (non-Javadoc)
     * @see javax.faces.component.UIComponent#processValidators(javax.faces.context.FacesContext)
     */
    public void processValidators(javax.faces.context.FacesContext context)
    {
        if (context == null) throw new NullPointerException("context");
        if (mustProcessed(context))
        {
            for (Iterator it = getFacetsAndChildren(); it.hasNext();)
            {
                UIComponent childOrFacet = (UIComponent) it.next();
                childOrFacet.processValidators(context);
            }
        }
    }
    
    

    /* (non-Javadoc)
     * @see javax.faces.component.UIComponent#processUpdates(javax.faces.context.FacesContext)
     */
    public void processUpdates(javax.faces.context.FacesContext context)
    {
        if (context == null) throw new NullPointerException("context");
        if (mustProcessed(context))
        {
            for (Iterator it = getFacetsAndChildren(); it.hasNext();)
            {
                UIComponent childOrFacet = (UIComponent) it.next();
                childOrFacet.processUpdates(context);
            }
        }
    }

    /**
     * Test for condition processing decoders/validators/updates
     * @param context current FacesContext
     * @return true if submitted parent AjaxContainer or current form.
     */
    private boolean mustProcessed(FacesContext context)
    {
        if ( !AjaxRendererUtils.isAjaxRequest(context)) {
            if (!isSubmitted() ) {
                return false;
            }
        }
        return true;
    }
    

	/* (non-Javadoc)
	 * @see javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
	 */
	public void broadcast(FacesEvent event) throws AbortProcessingException {
		// perform default
		super.broadcast(event);
		if (event instanceof AjaxEvent) {
			// complete re-Render fields. AjaxEvent deliver before render response.
			setupReRender();
		}
	}


	/**
	 * Template methods for fill set of resions to render in subclasses.
	 */
	protected void setupReRender() {
		AjaxRendererUtils.addRegionsFromComponent(this,getFacesContext());
		
	}




	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.ajax.AjaxSource#addAjaxListener(org.ajax4jsf.framework.ajax.AjaxListener)
	 */
	public void addAjaxListener(AjaxListener listener) {
        addFacesListener(listener);		
	}


	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.ajax.AjaxSource#getAjaxListeners()
	 */
	public AjaxListener[] getAjaxListeners() {
        AjaxListener al[] = (AjaxListener [])
	    getFacesListeners(AjaxListener.class);
        return (al);

	}


	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.ajax.AjaxSource#removeAjaxListener(org.ajax4jsf.framework.ajax.AjaxListener)
	 */
	public void removeAjaxListener(AjaxListener listener) {
		removeFacesListener(listener);
		
	}
    
	public abstract boolean isAjaxSubmit();
	
	public abstract void setAjaxSubmit(boolean ajax);
 
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy