Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm learning JavaEE, and looking for some help. I'm trying to get all record from a Derby DB table to display on a xhtml page (dataTable). I received this error "java.lang.ClassCastException: java.util.Vector cannot be cast to java.util.ArrayList".

  1. Can someone explain the error and how I need to fix it?
  2. How do I trigger the data table to be shown only when the "Print" button is clicked? Thanks in advance

My named query:

NamedQueries({ @NamedQuery(name="getAllItemActivities", query="select c from LibraryItemActivity c") })

My bean manager:

private ArrayList activities;

public ArrayList getActivities() {

  return control.getActivites();

}

My control bean:

public ArrayList getActivites() {

  ArrayList<LibraryItemActivity> temp = (ArrayList<LibraryItemActivity>) em.createNamedQuery("getAllItemActivities").getResultList();

  return temp;

}

My html data table:

<h:form>
    <h:commandButton value = "Print"></h:commandButton>
    <h:dataTable value = "#{libraryBeanManager.activities}" var = "a">
        <h:column>
            <f:facet name="header">Book Title:</f:facet>
            #{a.libraryitemtitle}
        </h:column>
        <h:column>
            <f:facet name="header">Author:</f:facet>
            #{a.patron}
        </h:column>
        <h:column>
            <f:facet name="header">Publisher:</f:facet>
            #{a.activitytype}
        </h:column>
    </h:dataTable>  
</h:form>
share|improve this question
up vote 0 down vote accepted

javax.persistence.Query.getResultList() returns a java.util.List, not an ArrayList.

Change your ArrayList declarations to java.util.List.

share|improve this answer
    
it worked. Thanks Steve – tmt32mj Aug 4 at 22:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.