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

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
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
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
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
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

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