SlideShare a Scribd company logo
1 of 15
Download to read offline
Andreas Martin - Page 1
Master of Science in Business Information Systems FHNW
Pre-Master Information Systems
6. Presentation Layer
Andreas Martin
6. Presentation Layer
http://www.flickr.com/photos/dirk_hofmann/4200450207
Andreas Martin - Page 2
Presentation Layer
 Presentation layer
 JavaServer Faces
 Reference Project:
 Lending-Reference-Project-1: Book Lending Example using JSF
6. Presentation Layer
Presentation
Layer
http://www.flickr.com/photos/ajmexico/3281139507
The Latte Macchiato «Layering» Principle
http://www.flickr.com/photos/tf28/4367660424
Presentation Layer
Goal: Display 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)
Andreas Martin - Page 5
Business
Layer
Java EE 7 – Typical Layering including injected POJO’s
6. Presentation Layer
Persistence
Layer
@EntityManager
(JPA)
(JPA)@Entity
(JPA)
Session Bean
(EJB)
@PersistenceContext
Presentation
Layer
Facelets(JSF)@ManagedBean
(JSF)
Facelets
(JSF)
Users
Databases
@EJB / @Inject
POJO
@Inject
Andreas Martin - Page 6
Java EE 7 Web Applications
 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
Andreas Martin - Page 7
MVC (Model View Controller) Pattern
…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
Andreas Martin - Page 8
JSF Procedure
6. Presentation Layer
Web- Container
Faces Servlet
EJB
Entity
XHTML
(1) request
(6) response
(2)
(3.2)
(3.1)
(4)(5)
Business
Objects
(EJBs, etc.)
Controller
Managed
Bean
Andreas Martin - Page 9
Controller Example – Managed Bean
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.»
Andreas Martin - Page 10
Scopes
 Request-Scope (@RequestScoped )
 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
Andreas Martin - Page 11
Model Example - XHTML
6. Presentation Layer
Listing: Snippet of an XHTML Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<TITLE>Creates a new book</TITLE>
</h:head>
<h:body>
<H1>Create a new book</H1>
<HR />
<h:form>
<TABLE BORDER="0">
<TR>
<TD><h:outputLabel value="ISBN : " /></TD>
<TD><h:inputText value="#{bookController.book.isbn}" /></TD>
<TR>
</TR>
<TD><h:outputLabel value="Title :" />
</TD>
<TD><h:inputText value="#{bookController.book.title}" /></TD>
</TR>
</TABLE>
<h:commandButton value="Create a book"
action="#{bookController.doCreateBook}"
styleClass="submit" />
</h:form>
<HR /> <I>APress - Beginning Java EE 6</I>
</h:body>
</HTML>
Andreas Martin - Page 12
JavaServer Faces 2.0 – DZone Refcardz
6. Presentation Layer
Andreas Martin - Page 13
Lending-Reference-Project-1
Book Lending Example using JSF
6. Presentation Layer
Andreas Martin - Page 14
Hands-on-7
6. Presentation Layer
Model
View
Controller
Book EJBCustomer 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
DEMO
http://www.flickr.com/photos/jurvetson/489257240

More Related Content

Similar to 2014 Pre-MSc-IS-6 Presentation Layer

2014 Pre-MSc-IS-3 Persistence Layer
2014 Pre-MSc-IS-3 Persistence Layer2014 Pre-MSc-IS-3 Persistence Layer
2014 Pre-MSc-IS-3 Persistence Layerandreasmartin
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3phanleson
 
0012
00120012
0012none
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5phanleson
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces Skills Matter
 
Developing Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsDeveloping Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsSathish Chittibabu
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Strutsyesprakash
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Examplekamal kotecha
 
Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16Zainab Khallouf
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical OverviewSvetlin Nakov
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questionsDhiraj Champawat
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptrani marri
 

Similar to 2014 Pre-MSc-IS-6 Presentation Layer (20)

2014 Pre-MSc-IS-3 Persistence Layer
2014 Pre-MSc-IS-3 Persistence Layer2014 Pre-MSc-IS-3 Persistence Layer
2014 Pre-MSc-IS-3 Persistence Layer
 
JSF2 and JSP
JSF2 and JSPJSF2 and JSP
JSF2 and JSP
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
 
0012
00120012
0012
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
 
Java EE and Glassfish
Java EE and GlassfishJava EE and Glassfish
Java EE and Glassfish
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate
HibernateHibernate
Hibernate
 
Developing Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsDeveloping Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring tools
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 

More from andreasmartin

A Case Modelling Language for Process Variant Management in Case-based Reasoning
A Case Modelling Language for Process Variant Management in Case-based ReasoningA Case Modelling Language for Process Variant Management in Case-based Reasoning
A Case Modelling Language for Process Variant Management in Case-based Reasoningandreasmartin
 
2014 Pre-MSc-IS-5 Process Layer
2014 Pre-MSc-IS-5 Process Layer2014 Pre-MSc-IS-5 Process Layer
2014 Pre-MSc-IS-5 Process Layerandreasmartin
 
2014 Pre-MSc-IS-2 Infrastructure
2014 Pre-MSc-IS-2 Infrastructure2014 Pre-MSc-IS-2 Infrastructure
2014 Pre-MSc-IS-2 Infrastructureandreasmartin
 
2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layering
2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layering2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layering
2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layeringandreasmartin
 
2014 Pre-MSc-IS-0 Information Systems Modelling and Design
2014 Pre-MSc-IS-0 Information Systems Modelling and Design2014 Pre-MSc-IS-0 Information Systems Modelling and Design
2014 Pre-MSc-IS-0 Information Systems Modelling and Designandreasmartin
 
Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...
Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...
Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...andreasmartin
 

More from andreasmartin (6)

A Case Modelling Language for Process Variant Management in Case-based Reasoning
A Case Modelling Language for Process Variant Management in Case-based ReasoningA Case Modelling Language for Process Variant Management in Case-based Reasoning
A Case Modelling Language for Process Variant Management in Case-based Reasoning
 
2014 Pre-MSc-IS-5 Process Layer
2014 Pre-MSc-IS-5 Process Layer2014 Pre-MSc-IS-5 Process Layer
2014 Pre-MSc-IS-5 Process Layer
 
2014 Pre-MSc-IS-2 Infrastructure
2014 Pre-MSc-IS-2 Infrastructure2014 Pre-MSc-IS-2 Infrastructure
2014 Pre-MSc-IS-2 Infrastructure
 
2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layering
2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layering2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layering
2014 Pre-MSc-IS-1 Java Enterprise Edition and Information Systems Layering
 
2014 Pre-MSc-IS-0 Information Systems Modelling and Design
2014 Pre-MSc-IS-0 Information Systems Modelling and Design2014 Pre-MSc-IS-0 Information Systems Modelling and Design
2014 Pre-MSc-IS-0 Information Systems Modelling and Design
 
Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...
Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...
Integrating an Enterprise Architecture Ontology in a Case-based Reasoning App...
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

2014 Pre-MSc-IS-6 Presentation Layer

  • 1. Andreas Martin - Page 1 Master of Science in Business Information Systems FHNW Pre-Master Information Systems 6. Presentation Layer Andreas Martin 6. Presentation Layer http://www.flickr.com/photos/dirk_hofmann/4200450207
  • 2. Andreas Martin - Page 2 Presentation Layer  Presentation layer  JavaServer Faces  Reference Project:  Lending-Reference-Project-1: Book Lending Example using JSF 6. Presentation Layer
  • 4. The Latte Macchiato «Layering» Principle http://www.flickr.com/photos/tf28/4367660424 Presentation Layer Goal: Display 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)
  • 5. Andreas Martin - Page 5 Business Layer Java EE 7 – Typical Layering including injected POJO’s 6. Presentation Layer Persistence Layer @EntityManager (JPA) (JPA)@Entity (JPA) Session Bean (EJB) @PersistenceContext Presentation Layer Facelets(JSF)@ManagedBean (JSF) Facelets (JSF) Users Databases @EJB / @Inject POJO @Inject
  • 6. Andreas Martin - Page 6 Java EE 7 Web Applications  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
  • 7. Andreas Martin - Page 7 MVC (Model View Controller) Pattern …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
  • 8. Andreas Martin - Page 8 JSF Procedure 6. Presentation Layer Web- Container Faces Servlet EJB Entity XHTML (1) request (6) response (2) (3.2) (3.1) (4)(5) Business Objects (EJBs, etc.) Controller Managed Bean
  • 9. Andreas Martin - Page 9 Controller Example – Managed Bean 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.»
  • 10. Andreas Martin - Page 10 Scopes  Request-Scope (@RequestScoped )  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
  • 11. Andreas Martin - Page 11 Model Example - XHTML 6. Presentation Layer Listing: Snippet of an XHTML Page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <TITLE>Creates a new book</TITLE> </h:head> <h:body> <H1>Create a new book</H1> <HR /> <h:form> <TABLE BORDER="0"> <TR> <TD><h:outputLabel value="ISBN : " /></TD> <TD><h:inputText value="#{bookController.book.isbn}" /></TD> <TR> </TR> <TD><h:outputLabel value="Title :" /> </TD> <TD><h:inputText value="#{bookController.book.title}" /></TD> </TR> </TABLE> <h:commandButton value="Create a book" action="#{bookController.doCreateBook}" styleClass="submit" /> </h:form> <HR /> <I>APress - Beginning Java EE 6</I> </h:body> </HTML>
  • 12. Andreas Martin - Page 12 JavaServer Faces 2.0 – DZone Refcardz 6. Presentation Layer
  • 13. Andreas Martin - Page 13 Lending-Reference-Project-1 Book Lending Example using JSF 6. Presentation Layer
  • 14. Andreas Martin - Page 14 Hands-on-7 6. Presentation Layer Model View Controller Book EJBCustomer 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