File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » JSF
Bookmark "Problem with dynamic dataTable generation" Watch "Problem with dynamic dataTable generation" New topic
Author

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

JSP

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

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

Bean


Exception :

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(JspValueExpression.java:107)
at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:246)
at javax.faces.webapp.UIComponentELTag.createComponent(UIComponentELTag.java:222)
at javax.faces.webapp.UIComponentClassicTagBase.createChild(UIComponentClassicTagBase.java:486)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:670)
at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1142)
at com.sun.faces.taglib.html_basic.DataTableTag.doStartTag(DataTableTag.java:382)
at org.apache.jsp.First_jsp._jspx_meth_h_005fdataTable_005f0(First_jsp.java:340)
at org.apache.jsp.First_jsp._jspx_meth_f_005fview_005f0(First_jsp.java:132)
at org.apache.jsp.First_jsp._jspService(First_jsp.java:83)

Please help me out. I am complete stuck.


Regards,
Gaurav
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: 15641
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with dynamic dataTable generation
 
Similar Threads
Dynamic dataTable issue
Multiple Data Tables
Problem with Dynamic DataTable.
Programmatically create HTMLextendeddatatable
Dynamic JSF, programatically adding components