This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JSF and the fly likes Problem with dynamic dataTable generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Problem with dynamic dataTable generation" Watch "Problem with dynamic dataTable generation" New topic

Problem with dynamic dataTable generation

Kumar Gaurav
Ranch Hand

Joined: Apr 08, 2008
Posts: 108
Hi All,

I need to create a table dynamically which means no of columns will vary and will be decided at run time. For that i have written a code but its not working. I am pasting here code and exception stacktrace:


<h:commandButton action="#{firstBean.createTable}"></h:commandButton>

<h:dataTable binding="#{firstBean.dataTable}" rendered="#{firstBean.renderFlag}" />


Exception :


org.apache.jasper.el.JspELException: /First.jsp(23,1) '#{firstBean.dataTable}' Cannot convert #{firstBean.dataTable} of type class java.lang.String to class javax.faces.component.UIComponent
at org.apache.jasper.el.JspValueExpression.getValue(
at com.sun.faces.application.ApplicationImpl.createComponent(
at javax.faces.webapp.UIComponentELTag.createComponent(
at javax.faces.webapp.UIComponentClassicTagBase.createChild(
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(
at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(
at com.sun.faces.taglib.html_basic.DataTableTag.doStartTag(
at org.apache.jsp.First_jsp._jspx_meth_h_005fdataTable_005f0(
at org.apache.jsp.First_jsp._jspx_meth_f_005fview_005f0(
at org.apache.jsp.First_jsp._jspService(

Please help me out. I am complete stuck.

Davie Lin
Ranch Hand

Joined: Aug 05, 2007
Posts: 294
your class is "FirstBean"

but you can't use "#{firstBean}" that's not what your declare your class as
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

There's a "code" button in the editor that you can use to wrap code, XML, and other stuff that you don't want to be reformatted. I applied it to your example. It makes it a lot easier to read!

For the record, I'm not sure what Davie means - JSF doesn't refer to classes, it refers to instances, so "firstBean" is correct. Assuming you defined an instance of FirstBean in your faces-config under the name of "firstBean", at least.

I can't see for certain what makes the system thing your datatable property is a String, but you didn't initialize it in a constructor and the code that creates it would only be executed AFTER the page was displayed and posted back by clicking on the commandButton. So initially it would be null and just possibly, that got turned into a String whose value was "null". And that would definitely NOT be a dataTable.

So create a public no-argument constructor for FirstBean and initialize the dataTable to a basic dataTable object and see if that helps.

Also, be a good chap and put braces around your conditional predicates. It makes them less likely to bite code maintainers.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Problem with dynamic dataTable generation
It's not a secret anymore!