3 Replies Latest reply on May 8, 2012 7:51 AM by rodrigo.uchoa

    Custom column renderer for richfaces scrollableDataTable

    kamalath

      Hi,

      Can anyone tell me how to add custom column renderer to the scrollableDataTable.

      The requirement we have is to have different view of columns for the same table. i.e first set of columns will display text only with some background color and second set of columns in the same table will be of more complex structure (i.e it will have image and text in it with different background color). And here columns are dyanmic(read from database)

      I tried below code but it doesnot seem to be working

      public void addColumn() {
      FacesContext facesContext = FacesContext.getCurrentInstance();
      facesContext.getRenderKit().addRenderer(HtmlColumn.COMPONENT_FAMILY, "org.richfaces.renderkit.CellRenderer", new CustomColumnRenderer());

      HtmlColumn col = new HtmlColumn();
      col.setRendererType("org.richfaces.renderkit.CellRenderer");
      HtmlOutputText outputText = new HtmlOutputText();
      outputText.setValue("dynamic column");
      col.setHeader(outputText);

      //scroll table binding instance
      htmlScrollableDataTable.setRendererType("org.ajax4jsf.Column");
      htmlScrollableDataTable.getChildren().add(col);
      }


      Where CustomColumnRenderer is my Custom class which extends CellRenderer.

      public class CustomColumnRenderer extends CellRenderer {

      public CustomColumnRenderer()
      {
      }

      public String styleClass(FacesContext context, UIComponent component)
      {
      StringBuffer styleClass = new StringBuffer();

      return styleClass.toString();
      }

      public void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent component)
      throws IOException
      {
      // code to handle custom display
      }

      public void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component)
      throws IOException
      {
      // code to handle custom display
      }

      protected Class getComponentClass()
      {
      return javax.faces.component.UIColumn.class;
      }
      }