Web Anwendungen Entwickeln mit JSF, Spring und Tomcat



Similar documents
Web Development in Java Live Demonstrations (Live demonstrations done using Eclipse for Java EE 4.3 and WildFly 8)

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Customer Bank Account Management System Technical Specification Document

Managed Beans II Advanced Features

JavaServer Faces 2.0: The Complete Reference

PRIMEFACES MOBILE USER S GUIDE

Java EE 6 Development with NetBeans 7

How To Write A Web Framework In Java

CrownPeak Java Web Hosting. Version 0.20

Course Name: Course in JSP Course Code: P5

Complete Java Web Development

Rapid Application Development. and Application Generation Tools. Walter Knesel

<Insert Picture Here> Hudson Security Architecture. Winston Prakash. Click to edit Master subtitle style

JSF Melih Sakarya. Java Server Faces PrimeFaces

JavaServer Faces 2.0. Bernd Bohmann. Matthias Weßendorf. Agenda. Agenda. IRIAN Deutschland Apache MyFaces Tobago CORE. Mehr als nur ein Web-Framework

Enterprise Application Development In Java with AJAX and ORM

Glassfish, JAVA EE, Servlets, JSP, EJB

SPRING INTERVIEW QUESTIONS

Portals, Portlets & Liferay Platform

Application Security

Web Applications and Struts 2

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

Developing modular Java applications

Java EE Web Development Course Program

GlassFish Security. open source community experience distilled. security measures. Secure your GlassFish installation, Web applications,

Grails 1.1. Web Application. Development. Reclaiming Productivity for Faster. Java Web Development. Jon Dickinson PUBLISHING J MUMBAI BIRMINGHAM

Recommended JSF Enhancements

Oracle Identity Analytics Architecture. An Oracle White Paper July 2010

APAC WebLogic Suite Workshop Oracle Parcel Service Overview. Jeffrey West Application Grid Product Management

This training is targeted at System Administrators and developers wanting to understand more about administering a WebLogic instance.

Stock Trader System. Architecture Description

Software Architecture Document

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

SSC - Web development Model-View-Controller for Java web application development

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

The Oracle Fusion Development Platform

Spring Security 3. rpafktl Pen source. intruders with this easy to follow practical guide. Secure your web applications against malicious

Framework Adoption for Java Enterprise Application Development

Running and Testing Java EE Applications in Embedded Mode with JupEEter Framework

Web Applications. Originals of Slides and Source Code for Examples:

Specialized Programme on Web Application Development using Open Source Tools

White Paper March 1, Integrating AR System with Single Sign-On (SSO) authentication systems

Case Study. Web Application for Financial & Economic Data Analysis Brainvire Infotech Pvt. Ltd Page 1 of 1

JSR-303 Bean Validation

Developer s Guide. Version 1.8

Developing ASP.NET MVC 4 Web Applications MOC 20486

JBS-102: Jboss Application Server Administration. Course Length: 4 days

Developer Tutorial Version 1. 0 February 2015

WebSphere Server Administration Course

In this chapter, we lay the foundation for all our further discussions. We start

Course Number: IAC-SOFT-WDAD Web Design and Application Development

... Introduction... 17

Getting Started Guide. Version 1.8

JBoss SOAP Web Services User Guide. Version: M5

Core Java+ J2EE+Struts+Hibernate+Spring

Supporting Multi-tenancy Applications with Java EE

Building an Agile PLM Web Application with JDeveloper and Agile 93 Web Services

WebSphere Training Outline

<Insert Picture Here> Building a Complex Web Application Using ADF and Siebel

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

JBoss Portlet Container. User Guide. Release 2.0

ASP.NET Overview. Ken Casada Developer Evangelist Developer & Platform Evangelism Microsoft Switzerland

Module Title: : Cloud Application Development

The Java EE 6 Platform. Alexis Moussine-Pouchkine GlassFish Team

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

Module 13 Implementing Java EE Web Services with JAX-WS

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

This presentation will provide a brief introduction to Rational Application Developer V7.5.

JAVA/J2EE DEVELOPER RESUME

SOA REFERENCE ARCHITECTURE: WEB TIER

Developing a highly dynamic web application for a large bank using rules-based technology

ActiveVOS Server Architecture. March 2009

Android Programming: Installation, Setup, and Getting Started

IBM WebSphere Server Administration

Securing JSF Applications Against the OWASP Top Ten. The OWASP Foundation JSF One Rich Web Experience Sep 2008

Building Web Applications, Servlets, JSP and JDBC

Master Thesis. Arnold Kemoli. Design and Implementation of a Dynamic Component based Web Application Framework

Developing ASP.NET MVC 4 Web Applications

Oracle Application Development Framework Overview

Java EE 6 development with Eclipse, Netbeans, IntelliJ and GlassFish. Ludovic Champenois Oracle Corporation

Java Servlet 3.0. Rajiv Mordani Spec Lead

Research Article. ISSN (Print) *Corresponding author Lili Wang

The end. Carl Nettelblad

Esigate Module Documentation

Business Application Services Testing

Core J2EE Patterns, Frameworks and Micro Architectures

Specialized Programme on Web Application Development using Open Source Tools

Install guide for Websphere 7.0

Oracle WebLogic Server 11g Administration

Building and Using Web Services With JDeveloper 11g

Operations and Monitoring with Spring

Spring 3.1 to 3.2 in a Nutshell. Sam Brannen Senior Software Consultant

What s New in IBM Web Experience Factory IBM Corporation

NetBeans IDE Field Guide

Google Web Toolkit (GWT) Architectural Impact on Enterprise Web Application

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

3 Techniques for Database Scalability with Hibernate. Geert Bevin - SpringOne 2009

Transcription:

Entwickeln mit JSF, Spring und Tomcat Ulm, AOI-Systeme Schulung, Beratung, Entwicklung Januar 2011

Übersicht 1 System Architecture

Übersicht 1 System Architecture 2

Übersicht 1 System Architecture 2 3

Übersicht 1 System Architecture 2 3 4

Domain Driven Design Two Tier Architecture Inversion of Control Übersicht 1 System Architecture Domain Driven Design Two Tier Architecture Inversion of Control 2 3 4

Domain Driven Design Two Tier Architecture Inversion of Control Domain Driven Design Necessary aspects of the domain are described by a model which can be used to solve the tasks (business logic, services) related to the domain. Building Blocks Entity, an object with an indentity (e.g. seat in a concert hall) Value Object, object with attributes (e.g. dollar bill) Aggregate, aggregate root (e.g. house) Service, operations not belonging to an object Repository, specialized repository objects retrieve the domain objects Factory, factory objects create domain objects

Domain Driven Design Two Tier Architecture Inversion of Control Application Architecture A typical enterprise application architecture consists of the following four conceptual layers: 1 (Presentation Layer): Responsible for presenting information to the user and interpreting user commands. 2 Application Layer: Coordinates the application activity. It holds the state (progress) of the application tasks. 3 Domain Layer: This layer contains information about the business domain. The business objects are held here. 4 Layer: This layer acts as a supporting library for all the other layers. It provides communication between layers.

Domain Driven Design Two Tier Architecture Inversion of Control Application and Domain Application Layer It holds the state of the services (application tasks). It does not hold the state of business objects Business logic is delegated to the domain layer. Domain Layer Implements business logic. The save, retrieve or modify operations of the business objects are delegated to the infrastructure layer.

Domain Driven Design Two Tier Architecture Inversion of Control and Displays and updates (domain) Value Objects. User requests are delegated to the application layer. The repository layer retrives business objects from the entities (DAOs) stored in a database. It does the object relational mapping of the DAOs to tables (of a relational database). It stores tables in a (relational) database (MySQL, HSQLDB).

Domain Driven Design Two Tier Architecture Inversion of Control

Domain Driven Design Two Tier Architecture Inversion of Control Two Tier Architecture Container A container is a selfcontained piece of software which is run independently of the application. We will be (explicitly) using two container in our application. 1 Tomcat, running the application (using JSF/Facelets). 2 Spring, running the database (using Hibernate) and access control (using spring-security). Resources are registered/injcected using descriptions in xml-files and/or by annotations in the Java-classes. The application can request/supply resources held by the container.

Domain Driven Design Two Tier Architecture Inversion of Control Tomcat container A page request (or PPR) is delegated to a servlet deployed with the application. The servlet has access to the reources of the container (external context). External context A Java class (Bean) exposes its constructor (methods, fields) to the container. On request an instance of the class is created, requested resources are injected, and the class is put into the context. application-context: only one instance. session-context: one instance for each (user-) session. request scoped: one (stateless) instance for each request. A Bean is a Java-class following certain conventions about method naming, construction, and behavior, i.e., it is serializable, it has a default constructor, and its properties have getters and setters.

Domain Driven Design Two Tier Architecture Inversion of Control Spring container Resources (Beans) and are created and held in an application context (as singletons or prototype). Context Spring context can be described in the deployment descriptor (deployed with the application) or as XmlApplicationContext (build during run-time). Spring is able to auto scan, detect and instantiate (application) beans or components. Resources (Beans, Java-classes) are accessable through Dependency Injection. The application (Java-class, Bean) can access resources via Bean reference to pre-defined (elsewhere) instances.

Domain Driven Design Two Tier Architecture Inversion of Control

Domain Driven Design Two Tier Architecture Inversion of Control Spring container We will be using two spring modules. Spring Core/ORM Spring allows you to define and inject resources like a JDBC Data-Source, a Hibernate Session-Factory, data access objects (DAOs), and bussines objects. Spring Security Page request are passed through a security filter (web.xml). Non authorized page request are redirected to a login page. Remember-me button allows long-time authentication. Allows password encryption and database (MySQL) usage.

Domain Driven Design Two Tier Architecture Inversion of Control Inversion of Control Replace instantiation with dependency injection! Instantiation public StockBoImpl() { this.stockdao = new StockDaoImpl(); } Injection (using the interface StockDao!) @Autowired public StockBoImpl(StockDao stockdao) { this.stockdao = stockdao; }

Domain Driven Design Two Tier Architecture Inversion of Control Init application context and use bean reference! Init context (spring) in a managed bean (tomcat) @ManagedBean(name = "applicationservice") @ApplicationScoped public class AppBookcase implements Serializable { ApplicationContext appcontext; public AppBookcase() { appcontext = new ClassPathXmlApplicationContext( "/config/beanlocations.xml"); }... public ApplicationContext getappcontext() { return appcontext; } } Use bean reference @ManagedBean @SessionScoped public class ViewBean { @ManagedProperty(value = "#{applicationservice}") private AppBookcase application; } public void setapplication(appbookcase application) { this.application = application;... StockBo stockbo = application.getappcontext().getbean(stockbo);... }

JSF Facelets Backing Beans Übersicht 1 System Architecture 2 JSF Facelets Backing Beans 3 4

JSF Facelets Backing Beans We use JSF to implement the Web-pages of the. Web-page description 1 Describe the elements of the page, i.e. what is to be displayed. 2 Describe the view of each element, i.e. how it is displayed (rendered). 3 Describe the value of the fields and the actions. Elements are JSF-tags defined in the tag libraries. The view of each tag is defined in the implementation of the tag library and can be customized using skins and/or css-styles. The value of the elements is defined in Backing-Beans (Java-classes). The same page can be used in different places, e.g, a page to request address details can be used in serveral places.

JSF Facelets Backing Beans Java Server Faces JSF Lifecycle The JSF lifecycle does (the plumbing) data transfer between web-pages and backing beans invokes actions (flow of control) and listeners (events).

JSF Facelets Backing Beans Extending JSF The standard JSF component libraries (core and html, prefixes f: and h: resp.) are part of the standard JSF implementations. Further component libraries and implemtations can be added (myfaces tomahawk, trinidad, primefaces, prefixes t: tr: and p:). Configuration JSF components can be configured (attributes, skins/themes, css-styles). JFS components use partial page requests (PPR) and have attributes to call custom Javascript or AJAX functions. See for example the primefaces showcase at http://www.primefaces.org/showcase/ui/home.jsf

JSF Facelets Backing Beans JSF components It is possible to develop custom components. Moving parts, artefacts UIComponent Class, the computational aspect implementing the logic of the component. Render Class, the view aspect (rendering), which generates HTML to be displayed in the browser. UI Component Tag Class, the tag handler class Tag Library Descriptor File, associates tag handler with usable tag It is possible to build JSF components using widgets from Web 2.0 libraries such as Dojo. See http://www.ibm.com/developerworks/web/library/wa-aj-jsfdojo/index.html

JSF Facelets Backing Beans Example JSF page <h:form id="stockform"> <p:fieldset legend="available Stocks" appendtobody="false"> <p:datatable id="stocktable" var="stock" value="#{viewbeanstockedit.stocks}" styleclass="topdatatable" > <p:column filterby="#{stock.stockcode}"> <f:facet name="header"> <h:outputtext value="code" /> </f:facet> <h:outputtext value="#{stock.stockcode}" /> </p:column> <p:column> <f:facet name="header"> <h:outputtext value="name" /> </f:facet> <h:outputtext value="#{stock.stockname}" /> </p:column> <p:column style="width:32px"> <p:commandbutton oncomplete="dialog.show()" image="ui-icon ui-icon-search" update="stockform:display"> <f:setpropertyactionlistener value="#{stock}" target="#{viewbeanstockedit.editstocklistener}" /> </p:commandbutton> </p:column> </p:datatable> <p:commandbutton value="addrow" actionlistener="#{viewbeanstockedit.addstock}" update="display" oncomplete="dialog.show()" > </p:commandbutton> </p:fieldset>

JSF Facelets Backing Beans <p:dialog header="stock Details" widgetvar="dialog" showeffect="fold" hideeffect="fold" modal="false" > <h:panelgrid columns="2" cellpadding="5" id="display"> <h:panelgroup> <h:outputtext value="stock Code: " /> <h:message for="inputtextstockname"></h:message> </h:panelgroup> <h:inputtext value="#{viewbeanstockedit.selectedstock.stockcode}" id="inputtextstockname" validator="#{viewbeanstockedit.validatestockcode}" required="#{param[ requirestockvalidation ]== 1 }" requiredmessage="value required" /> <h:panelgroup > <h:outputtext value="stock Name: " /> <h:message for="inputtextstockcode" styleclass="color:red;"></h:message> </h:panelgroup> <h:inputtext value="#{viewbeanstockedit.selectedstock.stockname}" id="inputtextstockcode" validator="#{viewbeanstockedit.validatestockname}" required="#{param[ requirestockvalidation ]== 1 }" requiredmessage="value required" /> <p:commandbutton value="save" actionlistener="#{viewbeanstockedit.savestock}" update="display stocktable"> <f:param name="requirestockvalidation" value="1"></f:param> </p:commandbutton> <p:commandbutton value="delete" actionlistener="#{viewbeanstockedit.deletestock}" update="display stocktable" disabled="#{!viewbeanstockedit.editstock}"> </p:commandbutton> </h:panelgrid> </p:dialog> </h:form>

JSF Facelets Backing Beans Facelets Facelets Facelets is the view declaration language (view-handler) for Java server faces (Java EE). Facelets converts HTML elements (with jsfc attribute) into the corresponding JSF components. Facelets builds the JSF component tree as defined by the view of a JSF application. Facelets supports the JSF UI components (templates).

JSF Facelets Backing Beans Templating with UIComponents A Web-page partitions the screen in logical regions (navigation, content, header, footer). A template defines the regions and includes contents from other files. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"> <head> <title><ui:insert name="title">default title</ui:insert></title> <link rel="stylesheet" type="text/css" href="#{request.contextpath}/css/pagelayout.css"/> </head> <body> <div id="header"> <ui:insert name="header"> <ui:param name="headerbean" value="#{applicationbean.header}" /> <ui:include src="/web-inf/template/header.xhtml"/> </ui:insert> </div>... <div id="content" > <ui:insert name="content"> Content defined in the templating file comes here! </ui:insert> </div>...

JSF Facelets Backing Beans Templating with UIComponents Files included by a template use the ui:component tag. Everything outside will be ignored. Parameters can be passed in from the template. <ui:component xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:panelgroup id="infopanel" layout="block" style="clear: both; padding: 20px;"> <p:menubar> <p:submenu label="new" url="#{viewbean.newurl}"/> <p:submenu label="edit" url="#{viewbean.editurl}"/> <p:submenu label="delete" url="#{viewbean.deleteurl}"/> <p:submenu label="properties" url="#{viewbean.propertiesurl}"/> </p:menubar> </h:panelgroup> </ui:component>

JSF Facelets Backing Beans Templating with UIComponents A templating page defines the content of (named) regions and passes parameters to the template. Eveything outside ui:composition tag will be ignored. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <ui:composition template="/web-inf/path/to/templateapp.xhtml"> <ui:param name="applicationbean" value="#{bmcapplicationbean}" /> <ui:define name="title">bmc Distribution</ui:define> <ui:define name="content"> <!-- use the form tag and define your page--> <h:form id="contentform"> This will be visible! </h:form> </ui:define> </ui:composition> </html>

JSF Facelets Backing Beans Backing Beans The dynamic content of the web-page (JSF-components) is taken from so called Backing Beans (other content is taken from resource files). For a Web-page, e.g. booksearch.xhtml we use two Java-classes. ViewBean and Controller classes BookSearchViewBean.java to access data values (domain). BookSearchController.java to access values concerning the application process status. In general, a viewbean can be seen as interface to information held in the business objects (domian layer) whereas the Controller(-Bean) is the interface to the process application status (application layer).

JSF Facelets Backing Beans Backing Beans In a typical application Backing-Beans are stateful, i.e. defined in session scope. Page request (navigation) are handled in the Controller Bean. Process validation (e.g. data consistency on page entry or page leave) are done in the Controller Bean.

Übersicht 1 System Architecture 2 3 4

Application Layer The Application (process) as hierarchical structure The application consists of processes. Each process consists of process steps. Each process step corresponds to a Web-page (Dialog, Portlet) Processes are independent from each other, i.e., it is possible to navigate from one process to another. Process-steps are sequential, i.e. it is not possible to leave or enter a step in a non-consistent state. A process tries to model a (business) service. A process step is a means to display or gather information to and from the user.

Domain The Domain Layer implements a model of the domain and services to solve the tasks. Usually we distinguish The Data model (database) which represents the domain knowlegde. The Services which implement the manipulation of the data. Sevices are called from the application layer. Data is displayed (and modified) in the. Business Objects implemented in the infrastructure are used to persist data. Decouple Layers Dependency injection and bean reference allows to decouple the layers.

Übersicht 1 System Architecture 2 3 4

Repository Layer Implements the API, i.e. implements the Business Objects (BOs) which persist the domain objects (of the domain layer). The implementation of the Business Objects aggregates the domain objects from (simpler) Data Acess Objects (DAOs). The DAOs are mapped to database tables which in turn are stored in a database. Spring allows us to configure the mapping and the database. Mapping is done using Hibernate. Tables are stored in HSQLDB and MySQL databases. Web-sevices, access to e.g. the enterprise service bus and interfaces to other (legacy) systems are also implemented in the infrastructure layer.

References The Java EE 6 Tutorial http://download.oracle.com/javaee/6/tutorial/doc/ The Hibernate reference documentation http://www.hibernate.org/docs Spring Framework http://static.springsource.org/spring/docs/3.0.x/spring-frameworkreference/html Spring Security http://static.springsource.org/spring-security/site/reference.html An Introduction to Domain Driven Design, D. Haywood http://www.methodsandtools.com/archive/archive.php?id=97