JSF dataTable dynamic columns Problem
843842Dec 7 2004 — edited Oct 17 2008Hello everybody,
I'm trying to display a table with a dynamic number of columns. I found only 1 topic on the matter and tried it out.
The JSP Page has this tag:
<h:dataTable binding="#{ViewBean.dataTable}"
value= "#{ViewBean.tableRows}"
var= "#{row}" />
My "viewBean" contains the following code:
In constructor:
dataTable = new UIData();
//This one contains a simple list of 10 integers so that 10 rows are rendered, just for testing.
public ArrayList getTableRows ()
{
ArrayList lst = new ArrayList();
for (int n=0; n<10; n++) {
lst.add(new Integer(n));
}
return lst;
}
//Now my databinding thingy:
public UIData getDataTable()
{
UIColumn col;
UIOutput out = null;
Application app = app = FacesContext.getCurrentInstance().getApplication();
int colCount = 3;
for(int j = 0; j < colCount; ++j) {
out = new UIOutput();
col = new UIColumn();
ValueBinding vb = app.createValueBinding("#{" + j + "}"); //just a simple expression with nothing difficult in it.
out.setValueBinding("value", vb);
out.setRendererType("Text");
col.getChildren().add(out);
dataTable.getChildren().add(col);
}
return dataTable;
}
Now the error I get:
[com.sun.faces.el.ValueBindingImpl] getValue(ref=ViewBean.tableRows)
[com.sun.faces.el.VariableResolverImpl] resolveVariable: Resolved variable:biz.mbisoftware.ep.view.ListView@ee0373
[com.sun.faces.el.ValueBindingImpl] getValue Result:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[com.sun.faces.el.ValueBindingImpl] -->Returning [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[com.sun.faces.renderkit.html_basic.HtmlBasicRenderer] Begin encoding component _id2
[com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer] component.getValue() returned Name
[com.sun.faces.renderkit.html_basic.HtmlBasicRenderer] Value to be rendered Name
[com.sun.faces.renderkit.html_basic.ButtonRenderer] Begin encoding children _id0
[com.sun.faces.renderkit.html_basic.HtmlBasicRenderer] Begin encoding component _id3
[com.sun.faces.el.ValueBindingImpl] getValue(ref=1)
[com.sun.faces.el.ValueBindingImpl] getValue Result:1
[com.sun.faces.el.ValueBindingImpl] -->Returning 1
[com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer] component.getValue() returned 1
[com.sun.faces.application.ApplicationImpl] Created converter of type javax.faces.convert.LongConverter
[com.sun.faces.renderkit.html_basic.HtmlBasicRenderer] Value to be rendered 1
[com.sun.faces.taglib.html_basic.DataTableTag] id: null class: com.sun.faces.taglib.html_basic.DataTableTag
java.lang.NullPointerException
...long traceback...
Anyone has an idea what happened, or why it's not working? I have no clue.
Thx for your time.
Bjoern