Day 9-EL, RB, Spring Framework, IOC, DI.
Day 9-EL, RB, Spring Framework, IOC, DI.
Training
2016
FOUNDATION TRAINING
Expression Language and
Introduction to Spring 1
Deloitte Training 2016
3
Objectives of Day 9 Deloitte Training 2016
Work on
Maven Archetypes
4
Accessing Implicit Objects Deloitte Training 2016
Using EL
EL provides implicit objects that can be used to easily access
all implicit objects and scoped variables of JSP.
The following code snippet shows the use of an implicit
object:
My Email is: ${initParam.myEmail}
5
Accessing JavaBean Using EL Deloitte Training 2016
6
Handling Null Values Deloitte Training 2016
Using EL
One of the advantages of EL is that it can handle null values,
and therefore avoid throwing an exception.
If you try to display the value of an undefined variable by using
the EL expression, nothing will be displayed.
For example, if the variable, var is not declared and assigned a
value, but you are retrieving the value in the JSP page, it will not
throw an exception. The following code snippet shows this
implementation:
The value is: ${var}
7
Operators Supported by EL Deloitte Training 2016
8
Custom Tags Deloitte Training 2016
Reusability
9
contd.. Deloitte Training 2016
Custom tags can be classified into the following categories:
Empty tags
<td:welcome />
The following code snippet shows a custom tag that contains a JSP
scripting element as its body:
<td:welcome>
<%=today_date%>
</td:welcome>
10
contd.. Deloitte Training 2016
11
Using Custom Tags Deloitte Training 2016
You can use custom tags in a JSP page after creating the desired tag
handlers and TLD file(s). To use custom tags in a JSP page, you need to
perform the following tasks:
1. Place the desired TLD file(s) in the WEB-INF folder of the Web
application.
2. Place the class file of the tag handler in the WEB-INF/classes
folder of the Web application.
3. Add a taglib directive in the desired JSP page, as shown in the
following code snippet:
<%@ taglib prefix="ct" uri="/WEB-INF/tld1.tld"%>
4. Use the custom tag at the desired location in the JSP page, as
shown in the following code snippet:
<ct:TestTag/>
12
Deloitte Training 2016
Spring
Introduction and Background
Background –
Applications developed using J2EE consist of many
components.
These components belong to different frame works either
within Java/J2EE or exterior.
Application server offers transaction management,
multithreading, security, etc.
Despite this, the result is heavy weight application which
includes services even when not needed.
Developers and architects spend lot of time in setting up
configurations, using xml files.
contd..
The 'look-up' problem.
When a component C1 requires another component C2,
then C1 itself is responsible for looking up the C2 as it
depends upon.
This look-up happens by name, so the name of the
dependency is hardcoded in the component (code or
deployment descriptor).
Components communicate with each other from J2EE
application servers of different vendors is almost always
problematic.
Many components do not need all the services the
application server provided, but since there was no other API
to build components, all your components became heavy
weight, bloating the application.
contd..
Coding against the J2EE standards is very cumbersome, as
user needs to comply to several seemingly arbitrary rules,
and write code that is not so Object Oriented.
The classes have to be implemented in a very specific way,
which coupled the business logic to the J2EE classes.
The code less extensible, and not very test friendly as it uses
specific J2EE classes and interfaces.
The code cant be run in a unit test, since it presumes all
kinds of services present, normally provided by the J2EE
application server i.e. it is not testable outside of the
container.
Deploying a J2EE application in a container and starting it
up can be a very time-consuming task, so not very ideal if
test cases need to run unit tests regularly.
contd..
Solution is to write just POJOs, without the J2EE standards
overhead.
No overhead to implement any interfaces or extend from
other classes,
Clean implementation and design of domain with regular
Java classes.
Disadvantage with POJOs is cannot benefit from the
services provided by the container, such as transaction
management, remoting, etc.
SPRING INTRODUCTION
Spring provides a framework that integrates all kinds of Java
technologies/API's and makes it possible to use them with
simple POJO's.
Spring does not reinvent the wheel. It provides a nice and
elegant way to use existing technologies viz.. EJB, JDO,
Hibernate, Toplink, JMS, etc. This is accomplished by several
support classes and 'templates‘.
The programming model is built upon Inversion of Control
and Aspect-Oriented Programming. The user code need not
have Spring references all over the place.
Spring integrates easily using these techniques by placing
specific frameworks where needed.
Inversion of Control
Introduction –
Developing an application, involves dependencies between
and on components, services, classes etc.
These are 'wired’ together on the spot where needed.