Information Systems FHNW Pre-Master Information Systems 6. Presentation Layer Andreas Martin 6. Presentation Layer http://www.flickr.com/photos/dirk_hofmann/4200450207
of information, processing / forwarding of user interactions. Technologies: JavaServer Faces (JSF), JavaServer Pages (JSP), Servlets, etc. Business (Logic) Layer Goal: Reproduction of actions or «verbs» of the application (buy a book, print an order, deliver a book, etc.). Technologies: Enterprise Java Beans (EJBs) Persistence Layer Goal: Reproduction of database attributes, information or «nouns» in object / class attributes (Object-Relational Mapping, ORM). Technologies: Java Persistence API (JPA)
Servlet {1997}: Java classes, which creates HTML and processes HTTP- requests. Java ServerPages (JSP) {1999}: Quasi HTML- pages with Java code embedded. Java ServerFaces (JSF) {v1 2004; v2 2009}: Java ServerFaces is a web framework – the basic structure of a web application is given. Is based on Servlets and XHTML. JSF is a MVC (Model View Controller) architecture. Configuration over annotations. AJAX functionalities. 6. Presentation Layer
…using JSF 6. Presentation Layer Adapted from: Goncalves: Code and Models licensed under a CC BY-SA 3.0 License from https://github.com/agoncal/agoncal-book-javaee7
6. Presentation Layer Listing: BookController Managed Bean @ManagedBean @SessionScoped public class BookController { @EJB private BookEJB bookEJB; private Book book = new Book(); public String doCreateBook() { book = bookEJB.createBook(book); return "listBooks.xhtml"; } // Getters, setters } Enterprise JavaBean using Dependency Injection Entity Bean «View declaration; what is shown as next.»
Managed bean lives during a HTTP-request. View-Scope (@ViewScoped ) Managed bean live as long as a corresponding view is shown.. Session-Scope (@SessionScoped ): Managed beans exists during a user holds a session. Application-Scope (@ApplicationScoped ): One managed bean lives as long as the whole application is alive (usually in standalone desktop applications). 6. Presentation Layer @ApplicationScoped [CDI] @SessionScoped [CDI] @ViewScoped [JSF] @RequestScoped [CDI] @ConversationScoped [CDI] Life time
View Controller Book EJB Customer EJB Business cases: • Create a customer including address • …CRUD… Book Lending EJB <Entity> Address <Entity> Customer <Entity> Book Lending <Entity> Book n 1 0..n 0..m 1 Business cases: • Lend a book • Return a book • Show all lendings Business cases: • Create a book • …CRUD.. 1