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

org.ajax4jsf.tag.IncludeHandler 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.tag;

import java.io.IOException;

import javax.el.ELException;
import javax.el.VariableMapper;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;

import org.ajax4jsf.ajax.UIInclude;

import com.sun.facelets.FaceletContext;
import com.sun.facelets.el.VariableMapperWrapper;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.tag.jsf.ComponentConfig;
import com.sun.facelets.tag.jsf.ComponentHandler;

/**
 * @author shura
 *
 */
public class IncludeHandler extends ComponentHandler {
	
	private TagAttribute viewId;

	public IncludeHandler(ComponentConfig config) {
		super(config);
		this.viewId = getRequiredAttribute("viewId");
	}

	/* (non-Javadoc)
	 * @see com.sun.facelets.tag.jsf.ComponentHandler#onComponentCreated(com.sun.facelets.FaceletContext, javax.faces.component.UIComponent, javax.faces.component.UIComponent)
	 */
	protected void onComponentCreated(FaceletContext ctx, UIComponent c, UIComponent parent) {
		// TODO Auto-generated method stub
		super.onComponentCreated(ctx, c, parent);
	}
	
    protected void applyNextHandler(FaceletContext ctx, UIComponent c) 
    throws IOException, FacesException, ELException {
    	String path;
    	if(c.isRendered()){
    	if (c instanceof UIInclude) {
			UIInclude include = (UIInclude) c;
			path = include.getViewId();
//			if(include.isWasNavigation()){
//				c.getChildren().clear();
//			}
		} else {
			path = (String) c.getAttributes().get("viewId");
		}
        VariableMapper orig = ctx.getVariableMapper();
        ctx.setVariableMapper(new VariableMapperWrapper(orig));
        try {
            this.nextHandler.apply(ctx, c);
            ctx.includeFacelet(c, path);
        } finally {
            ctx.setVariableMapper(orig);
        }
    	} else {
    		c.getChildren().clear();
            this.nextHandler.apply(ctx, null);			
		}
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy