Hey guys,
I am trying to learn
JSP through books and online tutorials. I downloaded the Duke Bookstore app. Got this app running and have made some mods to the entry .jsp page. I am having trouble understanding what is going on with the Bean used in the following page. The bean is using a valiue of an object "value="<%=bookDBEJB%". I look at the code for bookDBEJB and I dont see where information is being used. At this point I am scratching my head!!!I hope that I have provided enough information for someone to point me in the right direction. Thanks in advance.
-------------------------------------------------------------------------
I received a reply to the post in the
ejb section.
THis is a JSP question, you would get better responses if posted in the JSP forum..
code:
<jsp:setProperty name="bookDB" property="database" value="<%=bookDBEJB%>" />
The above line is equivalent to calling bookDB.setDatabase(...), where the argument to the method is an object of type BookDBEJB, in your case whatever is represented by bookDBEJB.
Hope this helps.
---------------------------------------------------------------
Where does the object bookDBEJB get created?
Here is the code for the page that uses the bean:
<jsp:useBean id="bookDB" class="database.BookDB" scope="page" >
<jsp:setProperty name="bookDB" property="database" value="<%=bookDBEJB%>" />
</jsp:useBean>
<p><b>Lets see what happens here:</b></p>
<p><b><%=messages.getString("What")%></b></p>
<%
bookDB.setBookId("209");
BookDetails bd = bookDB.getBookDetails();
%>
------------------------------------------------------------------
package database;
import javax.ejb.*;
import javax.naming.*;
import java.sql.*;
import java.util.*;
import exception.*;
public class BookDB {
private
String bookId = "0";
private BookDBEJB database = null;
public BookDB () {
}
public void setBookId(String bookId) {
this.bookId = bookId;
}
public void setDatabase(BookDBEJB database) {
this.database = database;
}
public BookDetails getBookDetails() throws Exception {
try {
return (BookDetails)database.getBookDetails(bookId);
} catch (BookNotFoundException ex) {
throw ex;
}
}
public Collection getBooks() throws Exception {
try {
return database.getBooks();
} catch (BooksNotFoundException ex) {
throw ex;
}
}
public int getNumberOfBooks() throws Exception {
try {
return database.getNumberOfBooks();
} catch (BooksNotFoundException ex) {
throw ex;
}
}
}
----------------------------------------------------------
package database;
import java.util.*;
import javax.ejb.*;
import java.rmi.RemoteException;
import exception.*;
public interface BookDBEJB extends EJBObject {
public BookDetails getBookDetails(String bookId) throws RemoteException, BookNotFoundException;
public int getNumberOfBooks() throws RemoteException, BooksNotFoundException;
public Collection getBooks() throws RemoteException, BooksNotFoundException;
}