title: Extending PrimeFaces's dataTable handling of columns
body: <p>I'm trying to extend PrimeFaces's column component within a dataTable - primarily to create headers and to auto-insert the object's field based on a key value without having to manually insert column tags with their associated facets.</p>
  
  <p>I have the following in my my custom component overridng DataTableRenderer:</p>
  
  <pre><code>@Override
  public void encodeEnd(FacesContext context, UIComponent component)
          throws java.io.IOException {
      Object columnOrder = component.getAttributes().get("columnOrder");
      if (columnOrder != null) {
  
          component.getChildren().clear();
  
          Application application = context.getApplication();
          ExpressionFactory expressionFactory = application.getExpressionFactory();
  
          Column column = new Column();
  
          Object var = component.getAttributes().get("var");
          String varKey = columnOrder.toString();
  
          UIOutput header = (UIOutput) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
          header.setValue(varKey);
          column.getFacets().put("header", header);
  
          ValueExpression valExpr = expressionFactory.createValueExpression("#{" + var + "." + varKey + "}", String.class);
          UIOutput cell = (UIOutput) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
          cell.setValueExpression("value", valExpr);
  
  
          column.setStyleClass(varKey);
          column.getChildren().add(cell);
          component.getChildren().add(column);
  
          component.getAttributes().remove("columnOrder");
      }
      super.encodeEnd(context, component);
  }
  </code></pre>
  
  <p>and am calling it so</p>
  
  <pre><code>&lt;my:dataTable var="item" value="#{myBean.collection}" columnOrder="field" /&gt;
  </code></pre>
  
  <p>The header gets set correctly, but the cell outputs literally <em>#{item.field}</em> rather than evaluating the expression.</p>
  
  <p>The setStyleClass on the column component fails to have the desired effect as well.</p>
  
  <p>I'm guessing that I have got hold of the wrong end of the stick and am going the wrong way about this. </p>
  
  <p>NB. in this reduced example, I'm assuming that columnOrder is a single string and the header simply uses the key value, rather than a list of keys which look up in a bundle.</p>