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
 
 
 /*
  * AbstractProgressBarRenderer.java     Date created: 20.12.2007
  * Last modified by: $Author$
  * $Revision$   $Date$
  */
 package org.richfaces.renderkit.html;
 
 import java.util.Map;
 
 import  javax.faces.application.ResourceDependencies;
 import  javax.faces.application.ResourceDependency;
 import  javax.faces.component.UIComponent;
 import  javax.faces.context.FacesContext;
 import  javax.faces.context.PartialResponseWriter;
 import  javax.faces.context.PartialViewContext;
 
 import  org.ajax4jsf.javascript.JSReference;
 import  org.richfaces.component.MetaComponentResolver;
 import  org.richfaces.context.ExtendedPartialViewContext;
 import  org.richfaces.renderkit.MetaComponentRenderer;
Abstract progress bar renderer

Author(s):
Nick Belaevski
 
 @ResourceDependencies({ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
         @ResourceDependency(name = "jquery.js"),
         @ResourceDependency(name = "richfaces.js"),
         @ResourceDependency(library = "org.richfaces", name = "richfaces-queue.reslib"),
         @ResourceDependency(name = "richfaces-base-component.js"),
         @ResourceDependency(name = "richfaces-event.js"),
         @ResourceDependency(library = "org.richfaces", name = "progressBar.js"),
         @ResourceDependency(library = "org.richfaces", name = "progressBar.ecss") })
 public class ProgressBarBaseRenderer extends RendererBase implements MetaComponentRenderer {
     private static final JSReference BEFORE_UPDATE_HANDLER = new JSReference("beforeUpdateHandler");
     private static final JSReference AFTER_UPDATE_HANDLER = new JSReference("afterUpdateHandler");
     private static final JSReference PARAMS = new JSReference("params");
     private static final ProgressBarStateEncoder FULL_ENCODER = new ProgressBarStateEncoder(false);
     private static final ProgressBarStateEncoder PARTIAL_ENCODER = new ProgressBarStateEncoder(true);
     private static final int DEFAULT_MIN_VALUE = 0;
     private static final int DEFAULT_MAX_VALUE = 100;
 
     @Override
     protected void doDecode(FacesContext context, UIComponent component) {
         super.doDecode(contextcomponent);
 
         Map<StringStringparams = context.getExternalContext().getRequestParameterMap();
         if (params.get(component.getClientId(context)) != null) {
             PartialViewContext pvc = context.getPartialViewContext();
             pvc.getRenderIds().add(
                 component.getClientId(context) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
                     + .);
         }
     }

    
Check if component mode is AJAX

Parameters:
component
 
     protected boolean isAjaxMode(UIComponent component) {
         if (isResourceMode(component)) {
             return false;
         }
 
         SwitchType mode = getModeOrDefault(component);
 
         if (mode == .) {
            throw new IllegalArgumentException("Progress bar doesn't support 'server' mode");
        }
        return . == mode;
    }
    protected boolean isResourceMode(UIComponent component) {
        return component.getAttributes().get("resource") != null;
    }
    protected ProgressBarState getCurrentState(FacesContext context, UIComponent component) {
        ProgressBarState result;
        if (isResourceMode(component)) {
            result = .;
        } else {
            Number minValue = NumberUtils.getNumber(getMinValueOrDefault(component));
            Number maxValue = NumberUtils.getNumber(getMaxValueOrDefault(component));
            Number value = NumberUtils.getNumber(getValueOrDefault(component));
            if (value.doubleValue() < minValue.doubleValue()) {
                result = .;
            } else if (value.doubleValue() >= maxValue.doubleValue()) {
                result = .;
            } else {
                result = .;
            }
        }
        if (result == . || result == .) {
            if (!result.hasContent(contextcomponent)) {
                result = .;
            }
        }
        return result;
    }
    protected String getStateDisplayStyle(String currentStateString state) {
        if (currentState.equals(state)) {
            return null;
        }
        return "display: none";
    }
    protected String getSubmitFunction(FacesContext facesContext, UIComponent component) {
        if (!isAjaxMode(component)) {
            return null;
        }
        AjaxFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(facesContextcomponent);
        AjaxOptions options = ajaxFunction.getOptions();
        options.set("beforedomupdate");
        options.set("complete");
        options.setClientParameters();
        return ajaxFunction.toScript();
    }
    public void encodeMetaComponent(FacesContext context, UIComponent componentString metaComponentIdthrows IOException {
        if (..equals(metaComponentId)) {
            ProgressBarState state = getCurrentState(contextcomponent);
            ExtendedPartialViewContext partialContext = ExtendedPartialViewContext.getInstance(context);
            partialContext.getResponseComponentDataMap().put(component.getClientId(context),
                NumberUtils.getNumber(component.getAttributes().get("value")));
            PartialResponseWriter partialResponseWriter = context.getPartialViewContext().getPartialResponseWriter();
            partialResponseWriter.startUpdate(state.getStateClientId(contextcomponent));
            state.encodeStateForMetaComponent(contextcomponent);
            partialResponseWriter.endUpdate();
        } else {
            throw new IllegalArgumentException(metaComponentId);
        }
    }
    public void decodeMetaComponent(FacesContext context, UIComponent componentString metaComponentId) {
        throw new UnsupportedOperationException();
    }
    protected ProgressBarStateEncoder getEncoder(FacesContext facesContext, UIComponent component) {
        return isAjaxMode(component) ?  : ;
    }
    protected Object getMaxValueOrDefault(UIComponent component) {
        Object maxValue = ((AbstractProgressBarcomponent).getMaxValue();
        if (maxValue == null) {
            maxValue = ;
        }
        return maxValue;
    }
    protected Object getMinValueOrDefault(UIComponent component) {
        Object maxValue = ((AbstractProgressBarcomponent).getMinValue();
        if (maxValue == null) {
            maxValue = ;
        }
        return maxValue;
    }
    protected Object getValueOrDefault(UIComponent component) {
        Object value = ((AbstractProgressBarcomponent).getValue();
        if (value == null) {
            value = .;
        }
        return value;
    }
    protected SwitchType getModeOrDefault(UIComponent component) {
        SwitchType mode = ((AbstractProgressBarcomponent).getMode();
        if (mode == null) {
            mode = .;
        }
        return mode;
    }
New to GrepCode? Check out our FAQ X