| 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: 14572
|
|
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.
|
 |
 |
|
|
subject: Problem with dynamic dataTable generation
|
|
|