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

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

import javax.faces.component.UIComponent;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.ajax4jsf.ajax.UIInclude;
import org.ajax4jsf.framework.taglib.UIComponentTagBase;

/**
 * @author shura
 *
 */
public class IncludeTag extends UIComponentTagBase {
	
	private String viewId;

	/**
	 * @param viewId the viewId to set
	 */
	public void setViewId(String viewId) {
		this.viewId = viewId;
	}
	
	

	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.taglib.UIComponentTagBase#release()
	 */
	public void release() {		
		super.release();
		viewId = null;
	}



	/* (non-Javadoc)
	 * @see org.ajax4jsf.framework.taglib.UIComponentTagBase#setProperties(javax.faces.component.UIComponent)
	 */
	protected void setProperties(UIComponent component) {		
		super.setProperties(component);
		setStringProperty(component, "viewId", viewId);
	}



	/* (non-Javadoc)
	 * @see javax.faces.webapp.UIComponentTag#doEndTag()
	 */
	public int doEndTag() throws JspException {
		int i = super.doEndTag();
		return i;
	}



	/* (non-Javadoc)
	 * @see javax.faces.webapp.UIComponentTag#doStartTag()
	 */
	public int doStartTag() throws JspException {		
		int i = super.doStartTag();
		String resourcePath;
		UIComponent component = getComponentInstance();
		if(component.isRendered()){
		if (component instanceof UIInclude) {
			UIInclude includeComponent = (UIInclude) component;
			resourcePath = includeComponent.getViewId();
//			if(includeComponent.isWasNavigation()){
//				component.getChildren().clear();
//			}
		} else {
			resourcePath=(String) component.getAttributes().get("viewId");
		}
		JspWriter out = this.pageContext.getOut();
		ServletRequest request = this.pageContext.getRequest();
		ServletResponse response = this.pageContext.getResponse();
		RequestDispatcher rd = request.getRequestDispatcher(resourcePath);

        try {
			ServletResponseWrapperInclude responseWrapper = new ServletResponseWrapperInclude(response, out);
			rd.include(request,
			           responseWrapper);
			// Write buffered data, if any;
			responseWrapper.flushBuffer();
		} catch (Exception e) {
			throw new JspException(e);
		} 
		} else {
			component.getChildren().clear();
		}
		return i;
	}



	/* (non-Javadoc)
	 * @see javax.faces.webapp.UIComponentTag#getComponentType()
	 */
	public String getComponentType() {		
		return UIInclude.COMPONENT_TYPE;
	}

	/* (non-Javadoc)
	 * @see javax.faces.webapp.UIComponentTag#getRendererType()
	 */
	public String getRendererType() {
		return null;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy