How to Override SheetRenderer ?

UI Components for JSF
Post Reply
vankiemsau
Posts: 2
Joined: 08 Nov 2012, 04:56

08 Nov 2012, 05:04

My faces-config.xml file:

Code: Select all

   
 <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:

Code: Select all

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?

rubus
Posts: 517
Joined: 01 Oct 2010, 09:41
Location: Belgium

08 Nov 2012, 13:55

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 : viewtopic.php?f=3&t=1194

vankiemsau
Posts: 2
Joined: 08 Nov 2012, 04:56

12 Nov 2012, 09:31

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

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests