Tag Archives: Spring

Spring Book – Chapter 13 – Spring and JSF Integration

JSF being one of the very successful, prominent and well backed up web framework, the importance of integration between Spring and JSF is covered in full detail with meaningful pictures and example code in this chapter for readers who are beginners and experts alike.

JavaServer Faces (JSF) is a server side user interface component framework for developing Java technology-based web applications. Developed through the Java Community Process under JSR – 314, it establishes the standard for building server-side user interfaces and have gained tremendous acceptance over the period of time in the Java world. JavaServer Faces APIs are being designed keeping in mind that they can be leveraged by tools that will make web application development even easier and simpler.

This Chapter provides an introduction on how the in famous Spring Framework can be integrated with in famous web framework, Java Server Faces Technologies. The Chapter covers the necessary details of both the Spring Framework and JSF technology in the initial section in the context of Integration and then later on moves towards the concept of concepts which help in easing the integration between the two technologies.

JSF Overview

Before getting into the details of how Sping and JSF Integration, it is important to know basic details of JSF. The following initial sections of this Chapter will cover JSF in some detail so that initial context is set and we can understand the integration in a clear fashion.

JSF Architecture

JSF is based on Model-View-Controller (MVC) architecture. Since it is based on well know MVC design the applications can be designed in a simpler and easy fashion keeping maintainability factor intact. In earlier Chapters we have covered MVC design patter in detail, so I wouldn’t repeat the same in this Chapter.

MVC model’s main purpose is to separate model and presentation to enable developers to set focus on their core skills and collaborate more clearly. If the application demands creating different pages for presentation, developers can concentrate on the view layer rather than model and controller layer as developers have a provision to reuse code for controller and model already written with ease.

Pictorially JSF architecture keeping the essence of MVC design can be represented as shown in Figure 13-1 below.

fig13-01

Figure 13-1. JSF architecture showing off MVC design

JSF Lifecycle

The processing of a request is called lifecycle in JSF. There are different phases which are executed one after the other following “Chain of responsibilities” design pattern. Figure 13-2 below shows the JSF lifecycle.

fig13-02

Figure 13-2. JSF lifecycle

There are various phases constituting the JSF lifecycle. The various lifecycle phases can be summarized as follows:

  • Restore View
  • Apply Request Values
  • Process Validations
  • Update Model Values
  • Invoke Application
  • Render Response

Pictorially the various phases in the JSF lifecycle can be as shown in Figure 13-3 below.

fig13-03

Figure 13-3. JSf lifecycle phases

JSF application in many ways work very much similar to a typical desktop application comprising of components and events. In line with client application, components can create events and can react or listen to events. There are different types of events and there are various places where these events are created and invoked. The events can be classified into three different types as shown below:

  • System events – These events are created at various stages in an application or request lifetime. These events can be configured to evoke globally to all components and others which are related to a component.
  • Phase events – Phase events are coarse grained in nature and are broadcasted before and after every phase. You can use phase listener to check access before a phase is entered. You also have a provision of registering global phase event listener and per view phase event listener. Global phase listener are executed for all requests whereas per view listener only for a request of the specific view.
  • Application events – Application events are created by the application components. JSF has two types of events namely:
    • ValueChangeEvent
    • ActionEvent

Figure 13-4 below pictorially shows the events which are invoked at the various phases in the JSF lifecycle.

fig13-04

Figure 13-4. JSF lifecycle phases along with event invocation points

Page Visitors: 3877

Spring Book – Chapter 11 – Spring Web

Large number of enterprise web applications is developed using Java and forms a very integral part of any organization in modern day. Web applications have become more and more complex and it poses more and more challenges day by day. Having a good web framework should be able to address most of these challenges there by reducing the effort on the developer and allowing them to focus on implementation of actual business logic.

This Chapter introduces you to the Spring Frameworks web support and the various components in the Spring web stack. This is just an introduction to the Spring’s frameworks role in the web application development support.

The Chapter starts off by explaining the Spring web stack and the various components which it comprises. Later on it delves deep into each component and explains each one in detail. Following with the Spring philosophy it then covers the various integration possible with your Spring application. Since some integration is really important, these are covered as separate chapters later on.

A Little History

Before going deep into the Spring web stack, a little history about the Spring web stack development from its early days to present.

Spring started its journey in 2002 and Spring Web was part of the original Spring ecosystem and contained servlet/web tier tool for aiding web application development. Then came Spring Frameworks own MVC framework in the form of Spring MVC. Following the core principles of Spring, it allowed to integrate with other frameworks.

Then came the inclusion of Spring Portlet MVC which was contributed initially by Rutgers in April 2004. John Lewis started contributing changes and it got included in the main Spring code base along with Spring 2.0 release.

Spring Web Flow started as a sub project and its first release was in March 2005. Due to its innovative ideas and good acceptability in the industry after inception, it soon became an independent project and got its independent release version 1.0 released in the same year.

Over the period Spring MVC and Spring Web Flow evolved and is considered among the renounced web technology stack.

Spring Web Stack

Modern day web application posses high level of challenges, including the following:

  • Complexity continues to rise at an alarming rate
  • Necessity of exposing services to a larger audience
  • Ability to give users the best possible experience in the shortest possible of time
  • High expectations
  • Ability to build simpler applications
  • Cloud enablement

Ideally any web framework chosen for web application development should address the above challenges reducing much of the complexity for the developer. Spring provides a full stack web framework by gathering multiple libraries and frameworks useful for web development into a single unified software stack for web developers to use. It tries to address the rising complexities raised by web application development by building on top of the lightweight Spring container. Figure 11-1 shows the various components provided by the Spring web stack for developing web application using this foundation.

Figure 11-1. Spring Web Stack components

The Spring Web Stack gives you:

  • A unified programming model
  • Capability to handle multiple client types using the same foundation
  • Adaptability to choose the right approach according to the required use case

The various Spring web stack components are:

  • Spring Framework and Spring MVC
  • Spring Web Flow
  • Spring Security
  • Spring JavaScript
  • Spring Faces
  • Spring BlazeDS Integration

Page Visitors: 2689

Spring Book – Part III – Web Application Development Support by Spring

For any organization, business applications based on web has become a sort of mandate due to its evolvement over the period of time. Spring Framework provides modules which aids in developing web application infrastructure for the server side.

This part of the book contains Chapters which will help you in developing web application with the help of Spring Framework. More importantly it lets the reader understand the web application development support by the Spring Framework.

Chapter 11, “Spring Web”, introduces you to the Spring web stack as a whole. It introduces you to various components in the Spring web stack and also covers some basics around Spring web and other web technology facts like MVC framework and so forth.

Chapter 12, “Spring and Struts Integration”, purely looks into the integration of Spring Framework with the famous MVC framework, Struts in detail.

Chapter 13, “Spring and JSF Integration”, similar to Chapter 12, looks at integrating Spring Framework with another famous MVC framework Java Server Faces (JSF) in detail.

Chapter 14, “Spring MVC and Spring Web Flow”, goes into detail of Spring MVC, Spring Frameworks implementation of MVC pattern and Spring Web Flow in detail.

Chapter 15, “Web Application Security with Spring”, covers the most important aspect of any enterprise application, security. It covers Spring Security in detail with respect to web application security.

Chapter 11: Spring Web

Chapter 12: Spring and Struts Integration

Chapter 13: Spring and JSF Integration

Chapter 14: Spring MVC and Spring Web Flow

Chapter 15: Web Application Security with Spring

Page Visitors: 335

Spring Book – Chapter 8 – Data Access

One of the very important aspect in any enterprise application is the ability to get data in and out of your application with ease. Thinking on the same lines, Spring framework provides extensive support for data access. In this Chapter we will first explore the various data access technologies and then see the support provided by Spring for using these technologies in your application.

Spring effectively makes data access easier by managing the various resource for you, by providing abstraction and easy API helpers and by supporting all major data access technologies available in the industry so that you don’t have to get yourself bogged down to a particular technology. Going along with the Spring philosophy it lets your Spring application integrate to any data access technology with ease.

In this Chapter we will see the support given the Spring framework in interacting between data access layer and the service layer in your application. Spring compressive support for transaction management will be covered briefly as we have dedicated Chapter 9 for this specific topic. In this chapter we will also be covering various data access frameworks and technologies which the Spring framework integrates with almost ease.

Enterprise Data Access

Spring integrates and works just fine with all leading data access technologies at present available in market. Accessing eternal system like a database requires various resources at various stages. You will also have to look for resource contention and make sure that resource which is limited is managed properly and efficiently. Such resource management becomes critically important in mission critical enterprise application.

Putting the burden of maintaining these resources in an application to a developer not only puts additional pressure in a developer but also puts an additional risk on the overall application’s success. Spring provides comprehensive resource management capability which takes this burden away from the developer and entrust him with writing the actual business application logic.

Resource Management

As discussed earlier Spring integrates seamlessly with almost all data access technologies like JDBC, Hibernate, iBatis, JPA or JDO in a consistent way. Using Spring, you are not locked down to a particular technology and as case may be, you have the freedom of switching between the various technologies without worrying too much about the technology specific nitty-gritties. Figure 8-1 also shows the various classes which will be used to in the code samples in this chapter in various sections.

Figure 8-1. Spring Integration with well know data access technologies

Spring internally take care of the various resource management functionalities specific to data access technologies so that the developer concentrates on the actual application logic rather than data access technology specific coding.

Some of the key features which the Spring framework provides in resource management are:

  • Transaction Management
  • Connection Management
  • Exception Handling

In a typical application, the resource management capabilities are related with connection and transaction management. While trying to manage connection and transaction, there are exceptions that arise and resource management should also be capable of dealing these exceptions in timely and orderly fashion. Figure 8-2 shows a typical resource management scenario in an application.

Figure 8-2. A typical resource management scenario in any application

The following sections will look into these features of Spring in some detail so that you get a clear picture of what are the features which Spring transparently does for you in developing your application.

Page Visitors: 10603

Spring Book – Part II – Core Support by Spring

Any enterprise application is typically made of multiple components working in tandem to realize a business case. Usually the objects communicate with each other in some form to achieve this in an application. Achieving component interaction can be cumbersome and difficult to implement in any application. Even if it is considered easy to do, it might become very hard to replace a component with other component due to challenging business scenarios. Spring Framework does this sort of component interaction which can be seamlessly changed with changing scenarios efficiently and easily.

Part 2 builds on what you learned in Part 1 by delving into greater detail on Spring and its various features. Part 2 also focuses on the main goals and objectives that the Spring Framework addresses in an enterprise application. It’s quite a big part which spans eight Chapters in whole and gives the various core supports which the Spring framework provides, so that you can achieve these capabilities with ease while developing your application.

In Chapter 3, “Spring Quick Start,” I will explain how Spring works and is the basic principles it is based on. We’ll take a detailed look at bean definitions, accessing bean instance and various bean scopes available in the Spring Framework. We’ll also dig into Dependency Injection, the ApplicationContext class, and the ApplicationContext Lifecycle. We’ll do a deep dive into the various phases of the lifecycle so that you can get a solid understanding of the crux of the Spring Framework.

In Chapter 4 “Configuration Styles”, I will be explaining the various configuration styles that you can use in your Spring applications. On the way I will be giving brief explanation on the various annotations that you could use and finally gives a gives idea on the best practices for using various configuration styles in your application.

In Chapter 5, “Application Configuration – Simplified”, I will be giving some ideas as to how you can use he various simplification methods whereby you can reduce the configuration in your Spring application. I will also give you best practices that you can follow in some details with code samples.

In Chapter 6, “Enterprise Integration”, I will be covering enterprise integration capability which the Spring framework provides, which helps to easily integrate your application components to other components within the same application or third party application.

In Chapter 7, “Testing”, I will first be covering the general testing methodologies in any application to some detail. After that I will be covering each testing methodology along with the support provided by the Spring framework.

In Chapter 8, “Data Access”,  I will be giving you details as to how Spring framework supports in interacting between data access layer and the service layer in your application.

In Chapter 9, “Transaction Management”, transaction support by Spring framework is explained in full detail along with various basic transaction concepts which is key in any enterprise application that you will develop.

In Chapter 10, “Caching”, I will be explaining the various caching mechanisms that you can use in your applications and Spring’s support to do this integration with ease.

Chapter 3: Spring Quick Start

Chapter 4: Configuration Styles

Chapter 5: Application Configuration – Simplified

Chapter 6: Enterprise Integration

Chapter 7: Testing

Chapter 8: Data Access

Chapter 9: Transaction Management

Chapter 10: Caching

Page Visitors: 617

Spring – Application Monitoring – Performance Monitor

Thanks to my colleague for sharing this info on application monitoring using out of the box spring interceptors.

To put in place performance monitoring of service methods (methods annotated with @Service), do the following.

The interceptor class which will be used for this is org.springframework.aop.interceptor.PerformanceMonitorInterceptor.

In your spring application context configure the interceptor as below:-

The logger has to be set at trace level for the logging to happen

Page Visitors: 1814