Error Rendering Viewcustomer.xhtml] The class 'java.lang.String' does not have the property 'desc'.

elect ci.desc, ci.info "
                + "from c_info ci "
                + "where ci.id = (select a.c_id from account a where a.id="+acc_id+") ";
        q = em.createNativeQuery(sql);
        List list = q.getResultList();
        return list;
    }
 

If I use the above code, I get the below error:
SEVERE: Error Rendering View[/pages/customer.xhtml]
javax.el.PropertyNotFoundException: /pages/customer.xhtml @43,90 value="#{static.desc}": The class 'java.lang.String' does not have the property 'desc'.
From the exception, it looks like the "items" is a list of string from which you are trying to get the 'desc' and 'info'.
'items1' should be a list of object which contains 'desc' and 'info'.

Could you please check the values in 'items1'. ??

Here is how I declare items1;

private DataModel items1 = null; 
private DataModel items1 = null;
Let me explain how it is working.
If I change my query to view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
sql = "select ci.desc from c_info ci where ci.id = (select a.c_id from account a where a.id="+acc_id+") ";   
sql = "select ci.desc from c_info ci where ci.id = (select a.c_id from account a where a.id="+acc_id+") ";   means only one column and in my xhtml if I give view plaincopy to clipboardprint?

<h:outputText value="#{static}"/>  
<h:outputText value="#{static}"/>  instead of "static.desc" I can get the output. So I have problem when there are 2 columns. Please guide me how to display key and value if not using arraylist in xhtml.

Kindly try the following when you are selecting two columns in the query.

<p:column width="150">
<f:facet name="header">
<h:outputText value="#{bundle.d_label}"/>
</f:facet>
<h:outputText value="#{static[0]}"/>
</p:column>
<p:column width="150">
<f:facet name="header">
<h:outputText value="#{bundle.d_value}"/>
</f:facet>
<h:outputText value="#{static[1] }"/>
</p:column>

Actually, "items1" should be an instance of javax.faces.DataModel. For a list, that would be a ListDataModel.

If you reference a raw collection as a value property on a JSF2 dataTable, an anonymous DataModel will be built as a Decorator object for the collection and the dataTable will use it. That's OK as long as you want display-only, but if you intend to do things like put command buttons or links into the table rows, the anonymous model object won't be accessible to obtain the ex

Back  [1] [2] [3] [4] [5] [6] Next

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright