PDA

Click to See Complete Forum and Search --> : Constainer Persistant EJB Prob


Andy_Hollywood
Dec 12th, 2001, 05:17 PM
Hello

I am writing some ejb's that should simply get some details and return them to a servlet that calls the functions.

I have an entity bean called Book, which will hold the detail about a book.

I have a session bean that i want to hold a vector or array of all the books in the system.

How would i go about filling an array in my catalog with envery book entity?

Hope someonce can help

Cheers in advance

Andy

e-mulan
Dec 12th, 2001, 11:54 PM
in your session bean , add a method:

public BookData[] getPBookList() throws RemoteException{

try {

BookHome home = HomeFactory.getBookHome();
Enumeration enum = home.findAll();
Vector vec = new Vector();

if (enum != null) {
while (enum.hasMoreElements()) {
Object obj = enum.nextElement();
Book ejb = (Book)PortableRemoteObject.narrow(obj,Book.class);
BookData b = new BookData();
b.Id = ejb.getBookId();
b.name = ejb.getName();
b.description = ejb.getDescription();
p.price = ejb.getPrice();
vec.addElement(p);
}}
BookData[] book_array = new BookData[vec.size()];
vec.copyInto(book_array);
return book_array;
}
catch (Exception e) {
throw new RemoteException(e.getMessage());
}}

in your catalog (servlet?jsp?) component, call session bean's method. then you can get the array list of the books.