Board index JavaServer Faces General How to Override SheetRenderer ?

How to Override SheetRenderer ?

Components, Ajax Framework, Utilities and More.

Post 08 Nov 2012, 05:04

Posts: 2
My faces-config.xml file:

   
 <render-kit>      
         <renderer>
            <component-family>org.primefaces.component</component-family>
            <renderer-type>org.primefaces.component.SheetRenderer</renderer-type>
            <renderer-class>com.csc.scrumV.web.component.sheetList.ScrumVSheetRenderer</renderer-class>
         </renderer>
   </render-kit>


ScrumVSheetRenderer class:
public class ScrumVSheetRenderer extends SheetRenderer {
      public void encodeHeader(FacesContext context, Sheet sheet) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        ArrayList<String> headList= (ArrayList<String>) sheet.getValue();
        //fixed columns
        writer.startElement("thead", null);
        writer.startElement("tr", null);
       
        //index column header
        writer.startElement("th", null);
        writer.writeAttribute("class", Sheet.COLUMN_HEADER_CLASS, null);
        writer.startElement("div", null);
        writer.writeAttribute("class", Sheet.INDEX_CELL_CLASS, null);
        writer.endElement("div");
        writer.endElement("th");
       
        int columnIndex = 0;
        for(UIComponent child : sheet.getChildren()) {
            if(child instanceof Column && child.isRendered()) {
                Column column = (Column) child;
                boolean sortable = column.getValueExpression("sortBy") != null;
               
                String style = column.getStyle();
                String columnHeaderClass = sortable ? Sheet.COLUMN_HEADER_CLASS + " " + Sheet.SORTABLE_COLUMN : Sheet.COLUMN_HEADER_CLASS;
                String userStyleClass = column.getStyleClass();
                if(userStyleClass != null) {
                    columnHeaderClass = columnHeaderClass + " " + userStyleClass;
                }
       
                writer.startElement("th", null);
                writer.writeAttribute("id", column.getClientId(context), style);
                writer.writeAttribute("class", columnHeaderClass, null);
                if(style != null) {
                    writer.writeAttribute("style", style, null);
                }
               
                writer.startElement("div", null);
                writer.writeAttribute("class", Sheet.CELL_CLASS, null);
                if(column.getWidth() != -1) {
                    writer.writeAttribute("style", "width:" + column.getWidth() + "px", null);
                }

                if(sortable) {
                    writer.startElement("span", null);
                    writer.writeAttribute("class", Sheet.SORTABLE_COLUMN_ICON, null);
                    writer.endElement("span");
                }
               
                if (headList.isEmpty()) {
                   writer.write(getColumnCode(columnIndex));
            } else {
                writer.write(headList.get(columnIndex));
            }

                writer.endElement("th");
               
                columnIndex++;
            }
        }
       
        writer.endElement("tr");
        writer.endElement("thead");
       
        //frozen headers
        writer.startElement("tbody", null);
        writer.startElement("tr", null);
        writer.writeAttribute("class", Sheet.ROW_CLASS, null);
       
        //index column header
        writer.startElement("td", null);
        writer.writeAttribute("class", Sheet.COLUMN_HEADER_CLASS, null);
        writer.startElement("div", null);
        writer.writeAttribute("class", Sheet.INDEX_CELL_CLASS, null);
        writer.write("1");
        writer.endElement("div");
        writer.endElement("td");
       
        for(UIComponent child : sheet.getChildren()) {
            if(child instanceof Column && child.isRendered()) {
                Column column = (Column) child;
                String style = column.getStyle();
                String styleClass = column.getStyleClass();
       
                writer.startElement("td", null);
                if(style != null) writer.writeAttribute("style", style, null);
                if(styleClass != null) writer.writeAttribute("class", styleClass, null);

                writer.startElement("div", null);
                writer.writeAttribute("class", Sheet.CELL_CLASS, null);
                if(column.getWidth() != -1) {
                    writer.writeAttribute("style", "width:" + column.getWidth() + "px", null);
                }
               
                if(column.getHeader() != null) {
                    column.getHeader().encodeAll(context);
                }
                else if(column.getHeaderText() != null) {
                    writer.write(column.getHeaderText());
                }

                writer.endElement("div");
               
                writer.endElement("td");
            }
         }
       
        writer.endElement("tr");
        writer.endElement("tbody");
    }
}

When i debug it runs encodeHeader method into SheetRenderer not ScrumVSheetRenderer .Help me?


Posts: 515
Location: Belgium
Hello,

When I open the faces-config.xml file in the primefaces jar, I see that the component family is set to 'org.primefaces'. So that is probably your problem.

regards
Rudy
PrimeFaces version 3.5, Tomcat 7, Mojarra 2.1.13
PrimeFaces version 4.0, Glassfish 4.0
PrimeFaces version 5.0, WLS 12.1.2
If you haven't read the forum rules read them now : http://forum.primefaces.org/viewtopic.php?f=3&t=1194


Posts: 2
Thanks Rudy! I solved the problem as you found!
Regards
Sang Nguyen


Return to General