0

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>

1 Answer 1

0

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

Change your ArrayList declarations to java.util.List.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.