1 15 package org.apache.tapestry.vlib.pages; 16 17 import java.rmi.RemoteException ; 18 import java.text.DateFormat ; 19 20 import javax.ejb.FinderException ; 21 22 import org.apache.tapestry.IExternalPage; 23 import org.apache.tapestry.IRequestCycle; 24 import org.apache.tapestry.event.PageEvent; 25 import org.apache.tapestry.event.PageRenderListener; 26 import org.apache.tapestry.html.BasePage; 27 import org.apache.tapestry.vlib.VirtualLibraryEngine; 28 import org.apache.tapestry.vlib.ejb.Book; 29 import org.apache.tapestry.vlib.ejb.IOperations; 30 31 38 39 public abstract class ViewBook extends BasePage implements IExternalPage, PageRenderListener 40 { 41 private DateFormat _dateFormat; 42 43 public abstract Integer getBookId(); 44 45 public abstract void setBookId(Integer bookId); 46 47 public abstract Book getBook(); 48 49 public abstract void setBook(Book value); 50 51 public void activateExternalPage(Object [] parameters, IRequestCycle cycle) 52 { 53 Integer bookId = (Integer ) parameters[0]; 54 55 setBookId(bookId); 56 } 57 58 private void readBook() 59 { 60 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 61 Integer bookId = getBookId(); 62 63 int i = 0; 64 while (true) 65 { 66 IOperations bean = vengine.getOperations(); 67 68 try 69 { 70 setBook(bean.getBook(bookId)); 71 72 return; 73 } 74 catch (FinderException ex) 75 { 76 vengine.presentError("Book not found in database.", getRequestCycle()); 77 return; 78 } 79 catch (RemoteException ex) 80 { 81 vengine.rmiFailure( 82 "Remote exception obtaining information for book #" + bookId + ".", 83 ex, 84 i++); 85 } 86 } 87 88 } 89 90 public DateFormat getDateFormat() 91 { 92 if (_dateFormat == null) 93 _dateFormat = 94 DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, getLocale()); 95 96 return _dateFormat; 97 } 98 99 public void pageBeginRender(PageEvent event) 100 { 101 if (getBook() == null) 102 readBook(); 103 } 104 105 } | Popular Tags |