Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
License Agreement. Rich Faces - Natural Ajax for Java Server Faces (JSF) Copyright (C) 2007 Exadel, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 package org.richfaces.renderkit;
 
 
 import  javax.faces.component.UIComponent;
 import  javax.faces.context.FacesContext;
 import  javax.faces.context.ResponseWriter;
 import  javax.faces.render.Renderer;
 
 import  org.ajax4jsf.Messages;
 import  org.richfaces.log.Logger;
 import  org.richfaces.log.RichfacesLogger;
 import  org.richfaces.skin.Skin;
 import  org.richfaces.skin.SkinFactory;

Base Renderer for all chameleon Skin's and components. At most, make all common procedures and realise concrete work in "template" methods.

Author(s):
asmirnov@exadel.com (latest modification by $Author: alexsmirnov $)
Version:
$Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:51 $
 
 public abstract class RendererBase extends Renderer {
     private static final Logger LOG = RichfacesLogger.RENDERKIT.getLogger();
     private static final RendererUtils UTILS = RendererUtils.getInstance();
     private SkinFactory skinFactory = null;
 
     /*
      * (non-Javadoc)
      *
      * @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
      */
     @Override
     public void decode(FacesContext context, UIComponent component) {
 
         // Test for correct parameters.
         checkNull(contextcomponent"decode");
 
         if (!getComponentClass().isInstance(component)) {
             throw new IllegalArgumentException(Messages.getMessage(Messages.COMPONENT_CLASS_ERROR, ""getComponentClass()
                 .getName()));
         }
 
         if (.isDebugEnabled()) {
             .debug(Messages.getMessage(Messages.START_DECODING_COMPONENT_INFO, component.getClientId(context), component
                 .getClass().getName()));
         }
 
         preDecode(contextcomponent);
 
         // TODO - create set od common decoders ( UIInput, ActionSource etc. ) for process decoding.
         if (component.isRendered()) {
             String behaviorEventName = RenderKitUtils.decodeBehaviors(contextcomponent);
             if (behaviorEventName != null) {
                 queueComponentEventForBehaviorEvent(contextcomponentbehaviorEventName);
             }
 
             doDecode(contextcomponent);
         }
     }
 
     protected void queueComponentEventForBehaviorEvent(FacesContext context, UIComponent componentString eventName) {
 
     }
 
     protected void preDecode(FacesContext context, UIComponent component) {
     }
 
     protected void preEncodeBegin(FacesContext context, UIComponent componentthrows IOException {
     }
 
     /*
      * (non-Javadoc)
      *
      * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
      */
     @Override
    public void encodeBegin(FacesContext context, UIComponent componentthrows IOException {
        // Test for correct parameters.
        checkForCorrectParams(contextcomponent"encodeBegin");
        if (.isDebugEnabled()) {
            .debug(Messages.getMessage(Messages.START_ENCODING_COMPONENT_INFO, component.getClientId(context), component
                .getClass().getName()));
        }
        preEncodeBegin(contextcomponent);
        if (component.isRendered()) {
            ResponseWriter writer = context.getResponseWriter();
            doEncodeBegin(writercontextcomponent);
        }
    }
    private void checkForCorrectParams(FacesContext context, UIComponent componentString exceptionMessageParam) {
        checkNull(contextcomponentexceptionMessageParam);
        if (!getComponentClass().isInstance(component)) {
            throw new IllegalArgumentException(Messages.getMessage(Messages.COMPONENT_CLASS_ERROR,
                component.getClientId(context), getComponentClass().getName()));
        }
    }
    private void checkNull(Object contextObject componentString exceptionMessageParam) {
        if (context == null) {
            throw new NullPointerException(Messages.getMessage(Messages.CONTEXT_NULL_ERROR, exceptionMessageParam));
        }
        if (component == null) {
            throw new NullPointerException(Messages.getMessage(Messages.COMPONENT_NULL_ERROR, exceptionMessageParam));
        }
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
     */
    @Override
    public void encodeChildren(FacesContext context, UIComponent componentthrows IOException {
        // Test for correct parameters.
        checkForCorrectParams(contextcomponent"encodeBegin");
        if (.isDebugEnabled()) {
            .debug(Messages.getMessage(Messages.CHILDREN_ENCODING_COMPONENT_INFO, component.getClientId(context), component
                .getClass().getName()));
        }
        if (component.isRendered()) {
            ResponseWriter writer = context.getResponseWriter();
            doEncodeChildren(writercontextcomponent);
        }
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
     */
    @Override
    public void encodeEnd(FacesContext context, UIComponent componentthrows IOException {
        // Test for correct parameters.
        checkForCorrectParams(contextcomponent"encodeEnd");
        if (component.isRendered()) {
            ResponseWriter writer = context.getResponseWriter();
            doEncodeEnd(writercontextcomponent);
        }
        if (.isDebugEnabled()) {
            .debug(Messages.getMessage(Messages.FINISH_ENCODING_COMPONENT_INFO, component.getClientId(context), component
                .getClass().getName()));
        }
    }
    // ==========================================================
    // Protected common methods - for all Renderer's

    
Calculate current Skin for rendering.

Parameters:
context - current
Returns:
    protected Skin getSkin(FacesContext context) {
        if ( == null) {
             = SkinFactory.getInstance();
        }
        return .getSkin(context);
    }

    
Due to big number of common utility methods, base renderer divide to 2 classes - renderer and utils. since use static methods of utility class breack object paradigm, we use getter for concrete util instance. Developer can override any utility metod in 2 stages : 1) Create subclass of RendererUtils and override utility method. 2) Override this method for return instance of such subclass.

Returns:
Returns the utils.
    public RendererUtils getUtils() {
        return ;
    }

    
Get base component slass , targetted for this renderer. Used for check arguments in decode/encode.

Returns:
    protected Class<? extends UIComponent> getComponentClass() {
        // TODO - do we need this function?
        return UIComponent.class;
    }

    
Template method for custom decoding of concrete renderer. All parameters checking if performed in original decode method.

Parameters:
context
component
    protected void doDecode(FacesContext context, UIComponent component) {
    }

    
Template method for custom start encoding of concrete renderer. All parameters checking and writer is performed in original method.

Parameters:
writer
context
component
    protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
    }

    

Parameters:
writer
context
component
    protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
        // Hook method, must be overriden in renderers with special children processing
    }

    
Template method for custom finish encoding of concrete renderer. All parameters checking and writer is performed in original method.

Parameters:
writer
context
component
Throws:
IOException
    protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
    }

    
Render all children for given component.

Parameters:
facesContext
component
Throws:
IOException
    public void renderChildren(FacesContext facesContext, UIComponent componentthrows IOException {
        if (component.getChildCount() > 0) {
            for (UIComponent child : component.getChildren()) {
                child.encodeAll(facesContext);
            }
        }
    }
    public String concatClasses(Object... objects) {
        return HtmlUtil.concatClasses(objects);
    }
    public String concatStyles(Object... objects) {
        return HtmlUtil.concatStyles(objects);
    }
    public String getResourcePath(FacesContext contextString libraryString resourceName) {
        return RenderKitUtils.getResourcePath(contextlibraryresourceName);
    }
New to GrepCode? Check out our FAQ X