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.html;
 
 import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
 import static org.richfaces.renderkit.RenderKitUtils.renderAttribute;
 
 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.ResponseWriter;
 
 import  org.ajax4jsf.javascript.JSFunction;
 import  org.richfaces.renderkit.HtmlConstants;

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(library = "org.richfaces", name = "status.js") })
 @JsfRenderer(type = "org.richfaces.StatusRenderer", family = .)
 public class AjaxStatusRenderer extends RendererBase {
     private static final String START = "start";
     private static final String STOP = "stop";
     private static final String ERROR = "error";
     private static final String[] EVENT_NAMES = { "start""stop""error""success" };
 
     private static enum StatusState {
         // NOTE: states encode order is important for script!
         start(),
         error() {
             {
                 this.setOptional();
             }
         },
         stop() {
             {
                 this.setInitial();
             }
         };
         private String stateName;
         private String styleAttributeName;
         private String styleClassAttributeName;
         private String textAttributeName;
         private String defaultStyleClass;
         private boolean initial;
         private boolean optional;
 
         private StatusState(String stateName) {
             this. = stateName;
             this. = stateName + "Style";
             this. = stateName + "StyleClass";
             this. = stateName + "Text";
             this. = "rf-st-" + stateName;
         }
 
         public String getStyleAttributeName() {
             return ;
         }
 
         public String getStyleClassAttributeName() {
             return ;
         }
 
         public String getFacetName() {
             return ;
        }
        public String getTextAttributeName() {
            return ;
        }
        public String getDefaultStyleClass() {
            return ;
        }
        public boolean isInitial() {
            return ;
        }
        public boolean isOptional() {
            return ;
        }
        protected void setOptional() {
            this. = true;
        }
        protected void setInitial() {
            this. = true;
        }
    }
    protected void encodeState(FacesContext facesContextAbstractAjaxStatus statusStatusState statethrows IOException {
        Map<StringObjectstatusAttributes = status.getAttributes();
        UIComponent stateFacet = status.getFacet(state.getFacetName());
        String stateText = null;
        if (stateFacet == null) {
            stateText = (StringstatusAttributes.get(state.getTextAttributeName());
        }
        if (state.isOptional() && stateFacet == null && stateText == null) {
            return;
        }
        ResponseWriter writer = facesContext.getResponseWriter();
        writer.startElement(HtmlConstants.SPAN_ELEM, status);
        String stateStyle = (StringstatusAttributes.get(state.getStyleAttributeName());
        renderAttribute(facesContext, HtmlConstants.STYLE_ATTRIBUTE,
            HtmlUtil.concatStyles(stateStylestate.isInitial() ? null : "display:none"));
        String stateStyleClass = (StringstatusAttributes.get(state.getStyleClassAttributeName());
        renderAttribute(facesContext, HtmlConstants.CLASS_ATTRIBUTE,
            HtmlUtil.concatClasses(state.getDefaultStyleClass(), stateStyleClass));
        if (stateFacet != null && stateFacet.isRendered()) {
            stateFacet.encodeAll(facesContext);
        } else {
            if (stateText != null) {
                writer.writeText(stateTextnull);
            }
        }
        writer.endElement(HtmlConstants.SPAN_ELEM);
    }
    @Override
    public void encodeEnd(FacesContext context, UIComponent componentthrows IOException {
        super.encodeEnd(contextcomponent);
        AbstractAjaxStatus ajaxStatus = (AbstractAjaxStatuscomponent;
        ResponseWriter writer = context.getResponseWriter();
        writer.startElement(HtmlConstants.SPAN_ELEM, component);
        String clientId = component.getClientId(context);
        writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, clientId"id");
        for (StatusState state : StatusState.values()) {
            encodeState(contextajaxStatusstate);
        }
        writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
        writer.writeAttribute(HtmlConstants.TYPE_ATTR, HtmlConstants.TEXT_JAVASCRIPT_TYPE, null);
        JSFunction statusConstructor = new JSFunction("new RichFaces.ui.Status"clientId);
        Map<StringObjectoptions = new HashMap<StringObject>();
        Map<StringObjectattributes = ajaxStatus.getAttributes();
        for (String eventName : ) {
            String eventAttribute = "on" + eventName;
            HandlersChain handlersChain = new HandlersChain(contextcomponenttrue);
            handlersChain.addInlineHandlerFromAttribute(eventAttribute);
            handlersChain.addBehaviors(eventName);
            addToScriptHash(optionseventAttributehandlersChain.toScript(), null.);
        }
        addToScriptHash(options"statusName"attributes.get("name"));
        if (!options.isEmpty()) {
            statusConstructor.addParameter(options);
        }
        writer.writeText(statusConstructor.toScript(), null);
        writer.endElement(HtmlConstants.SCRIPT_ELEM);
        writer.endElement(HtmlConstants.SPAN_ELEM);
    }
    /*
     * (non-Javadoc)
     *
     * @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
     */
    @Override
    protected Class<? extends UIComponent> getComponentClass() {
        return AbstractAjaxStatus.class;
    }
New to GrepCode? Check out our FAQ X