org.ajax4jsf.framework.renderer.AjaxContainerRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajax4jsf Show documentation
Show all versions of ajax4jsf Show documentation
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.renderer;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.ajax4jsf.framework.ajax.AjaxContainer;
import org.ajax4jsf.framework.util.message.Messages;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Base renderer for all AJAX - subview components.
*
* @author [email protected] (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.6 $ $Date: 2006/11/13 15:20:40 $
*
*/
public class AjaxContainerRenderer extends AjaxChildrenRenderer {
public static final String AJAX_PARAMETER_NAME = "AJAXREQUEST";
public static final String AJAX_JSF_SCRIPT = "AJAX.js";
public static final String SARISSA_SCRIPT = "sarissa.js";
public static final String JSDOM_SCRIPT = "JSDOM_sarissa.js";
public static final String AJAX_VIEW_STATE_TAG = "span";
public static final String AJAX_VIEW_STATE_ID = "ajax-update-ids";
public static final String AJAX_RESULT_GROUP_TAG = "meta";
public static final String AJAX_RESULT_GROUP_ATTR = "content";
public static final String AJAX_RESULT_STYLE = "display: none";
public static final String AJAX_UPDATE_HEADER = "Ajax-Update-Ids";
static final Log log = LogFactory
.getLog(AjaxContainerRenderer.class);
public static final String AJAX_FLAG_HEADER = "Ajax-Response";
public static final String AJAX_LOCATION_HEADER = "Location";
/*
* (non-Javadoc)
*
* @see org.ajax4jsf.framework.renderer.RendererBase#getComponentClass()
*/
protected Class getComponentClass() {
// TODO Auto-generated method stub
return AjaxContainer.class;
}
/**
*
*
* @see javax.faces.component.UIComponent#encodeChildren(javax.faces.context.FacesContext)
* Since main function of component - render subset of components, for
* update on page,don't delegate this for renderer.
*
*/
public void encodeChildren(FacesContext context, UIComponent component)
throws IOException {
// Normal request - render all ...
log.debug(Messages.getMessage(Messages.RENDER_CHILDREN_NON_AJAX_INFO));
renderChildren(context, component);
}
/**
* @param context
* @param component
* @throws IOException
*/
public void encodeAjax(FacesContext context, UIComponent component)
throws IOException {
AjaxContainer container = (AjaxContainer) component;
// Iterate over all childrens, render it if nessesary...
log.debug(Messages.getMessage(Messages.RENDER_CHILDREN_AJAX_INFO));
// For MyFaces, view sequence number stored in hidden field.
// In case Ajax-based processing, we restore same sequence number, as
// for
// original page. In this reason, we can return to this page without
// change of view.
// Temporary removed, since caused exceptions in save state calls.
// Integer sequence = container.getSequence();
// if (null != sequence)
// {
// context.getExternalContext().getRequestMap().put(
// AjaxRendererUtils.SEQUENCE_PARAM, sequence);
// }
Set ids = AjaxRendererUtils.getSubmittedAjaxContainer(context,
container).getAjaxAreasToRender();
Set renderedAreas = container.getAjaxRenderedAreas();
if (!container.isRenderRegionOnly()) {
component = context.getViewRoot();
}
String path = AjaxRendererUtils.getAbsoluteId(component);
// if(! (component instanceof NamingContainer)){
path = path.substring(0, path
.lastIndexOf(NamingContainer.SEPARATOR_CHAR) + 1);
// } else {
// path+=NamingContainer.SEPARATOR_CHAR;
// }
encodeAjaxChild(context, component, path, ids, renderedAreas);
// Write information about encoded areas after submission.
AjaxRendererUtils.encodeAreas(context, component);
// if not submitted AJAX request, ignore children components.
}
/*
* always return true, since component must maintain set of rendered
* components.
*
* @see javax.faces.component.UIComponent#getRendersChildren()
*/
public boolean getRendersChildren() {
return true;
}
/*
* (non-Javadoc)
*
* @see org.ajax4jsf.framework.renderer.RendererBase#doDecode(javax.faces.context.FacesContext,
* javax.faces.component.UIComponent)
*/
protected void preDecode(FacesContext context, UIComponent component) {
super.preDecode(context, component);
String clientId = component.getClientId(context);
Map paramMap = context.getExternalContext().getRequestParameterMap();
if (log.isDebugEnabled()) {
log.debug(Messages.getMessage(
Messages.DECODE_AJAX_REQUEST_STATUS_INFO, clientId));
log.debug(Messages.getMessage(Messages.REQUEST_PARAMETERS_MAP,
paramMap.toString()));
}
Object ajaxParameter = paramMap.get(AJAX_PARAMETER_NAME);
if (null != ajaxParameter) {
((AjaxContainer) component).setAjaxRequest(true);
if (ajaxParameter.equals(clientId)) {
((AjaxContainer) component).setSubmitted(true);
} else {
// ((AjaxContainer) component).setSubmitted(false);
}
} else {
((AjaxContainer) component).setSubmitted(false);
((AjaxContainer) component).setAjaxRequest(false);
}
}
}