Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright ${year}, Red Hat, Inc. and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.richfaces.renderkit.html;
 
 import static org.richfaces.renderkit.HtmlConstants.CLASS_ATTRIBUTE;
 import static org.richfaces.renderkit.HtmlConstants.DIV_ELEM;
 import static org.richfaces.renderkit.HtmlConstants.ID_ATTRIBUTE;
 import static org.richfaces.renderkit.HtmlConstants.STYLE_ATTRIBUTE;
 import static org.richfaces.renderkit.RenderKitUtils.renderPassThroughAttributes;
 
 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.JSObject;

Author(s):
akolonitsky
Since:
2010-08-05
 
 @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 = "togglePanelItem.js"),
         @ResourceDependency(library = "org.richfaces", name = "accordionItem.js") })
 @JsfRenderer(type = "org.richfaces.AccordionItemRenderer", family = .)
 public class AccordionItemRenderer extends TogglePanelItemRenderer {
     private static final RenderKitUtils.Attributes HEADER_ATTRIBUTES = RenderKitUtils.attributes()
         .generic("style""headerStyle").generic("onclick""onheaderclick""headerclick")
         .generic("ondblclick""onheaderdblclick""headerdblclick")
         .generic("onmousedown""onheadermousedown""headermousedown")
         .generic("onmousemove""onheadermousemove""headermousemove")
         .generic("onmouseup""onheadermouseup""headermouseup");
 
     public AccordionItemRenderer() {
         super(false);
     }
 
     @Override
     protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
         doEncodeItemBegin(writercontextcomponent);
     }
 
     @Override
     protected void doEncodeItemBegin(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
 
         super.doEncodeItemBegin(writercontextcomponent);
         encodeHeader(context, (AbstractAccordionItemcomponent);
         encodeContentBegin(contextcomponent);
     }
 
     @Override
     protected String getStyleClass(UIComponent component) {
         return concatClasses("rf-ac-itm"attributeAsString(component"styleClass"));
     }
 
     @Override
     protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
 
         AbstractAccordionItem item = (AbstractAccordionItemcomponent;
 
         if (!item.isDisabled()) {
             super.doEncodeChildren(writercontextitem);
         }
     }
 
    @Override
    protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
        doEncodeItemEnd(writercontextcomponent);
    }
    @Override
    protected void doEncodeItemEnd(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
        encodeContentEnd(writercomponent);
        super.doEncodeItemEnd(writercontextcomponent);
    }
    private void encodeContentBegin(FacesContext context, UIComponent componentthrows IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.startElement(DIV_ELEM, component);
        writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses("rf-ac-itm-cnt"attributeAsString(component"contentClass")),
            null);
        writer.writeAttribute("id"component.getClientId(context) + ":content"null);
        AbstractTogglePanelTitledItem item = (AbstractTogglePanelTitledItemcomponent;
        if (!item.isActive() || item.isDisabled()) {
            writer.writeAttribute(STYLE_ATTRIBUTE, "display: none"null);
        }
    }
    private void encodeContentEnd(ResponseWriter writer, UIComponent componentthrows IOException {
        writer.endElement(DIV_ELEM);
    }
    private void encodeHeader(FacesContext contextAbstractAccordionItem componentthrows IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.startElement(DIV_ELEM, component);
        String stateCssClass = "rf-ac-itm-hdr-" + (component.isDisabled() ? "dis" : (component.isActive() ? "act" : "inact"));
        writer.writeAttribute(CLASS_ATTRIBUTE,
            concatClasses("rf-ac-itm-hdr"stateCssClassattributeAsString(component"headerClass")), null);
        writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context) + ":header"null);
        renderPassThroughAttributes(contextcomponent);
        .encodeHeader(writercontextcomponent);
        writer.endElement(DIV_ELEM);
    }
    @Override
    protected JSObject getScriptObject(FacesContext context, UIComponent component) {
        return new JSObject("RichFaces.ui.AccordionItem"component.getClientId(context), getScriptObjectOptions(context,
            component));
    }
    @Override
    protected Map<StringObjectgetScriptObjectOptions(FacesContext context, UIComponent component) {
        Map<StringObjectres = super.getScriptObjectOptions(contextcomponent);
        res.put("disabled", ((AbstractTogglePanelTitledItemcomponent).isDisabled());
        return res;
    }
    @Override
    protected Class<? extends UIComponent> getComponentClass() {
        return AbstractAccordionItem.class;
    }
New to GrepCode? Check out our FAQ X