01 <!-- ----------------------------------------------------------------------- -->
02 <!-- Shows all the Books in the database. -->
03 <!-- ----------------------------------------------------------------------- -->
04 <HTML>
05 <HEAD>
06 <%@ page errorPage="exception.jsp" %>
07 <link href="sample.css" rel="stylesheet"></link>
08 </HEAD>
09 <BODY>
10 <%@ include file="header.html" %>
11
12 This example issues query using Java Persistence Query Language to select
13 all books in the database.<p>
14 The query is: <B><pre>SELECT i FROM Book i</pre></B>
15 <HR>
16
17 <%@ include file="common_session.jsp" %>
18 <CENTER><H2>List of books</H2></CENTER>
19 <HR>
20
21 <DIV ALIGN="CENTER">
22 <TABLE CELLPADDING="2" CELLSPACING="2" WIDTH="100%">
23 <TR>
24 <TH>UID</TH>
25 <TH>Title</TH>
26 <TH>Author</TH>
27 <TH>Total Reviews</TH>
28 <TH>Rating</TH>
29 </TR>
30 <!-- ---------------------------------------------------------------------- -->
31 <!-- Calls the service to get the entire extent of Book. -->
32 <!-- and then iterates through the listed books to display one per row. -->
33 <!-- ---------------------------------------------------------------------- -->
34 <%
35 List<Book> books = serviceImpl.getAll(Book.class);
36 int i = 0;
37 for (Book book:books){
38 i++;
39 String style = (i%2==0) ? "spec" : "specalt";
40 String author = (book.getArtist()==null)
41 ? "" : book.getArtist().getName();
42 %>
43 <tr class="<%=style%>">
44 <td> <%=book.getId()%>
45 <td> <%=book.getTitle()%>
46 <td> <%=author%>
47 <td> <%=book.getReviews().size()%>
48 <td> <%=numberFormat.format(book.getRating())%>
49
50 <%
51 }
52 %>
53 </TABLE>
54 <DIV ALIGN="CENTER">
55
56 </BODY>
57 </HTML>
|