JBoss seam: agile Ria Development FRamewoRk

tastelessbeachInternet et le développement Web

12 nov. 2013 (il y a 7 années et 9 mois)

521 vue(s)

2 Developing the initial proDuct
4 Securing the application for releaSe
8 Simplifying the programming moDel
13 reDuce front-enD Development
effort with JBoSS Seam
16 integration framework
18 Scaling on a Dime with JBoSS Seam
19 agile ria Development framework
JBoss seam:
agile Ria Development FRamewoRk
By JacoB orShalick anD nirav aSSar
2 www.jboss.com
Rich Internet Applications (RIAs) are in great demand in today's technology-infused business world.
Customers want web applications that offer a rich, engaging experience and improve user productivity.
Yet, an increasingly competitive market continues to constrain IT budgets and require rapid time-to-market
to ensure product survival.
In order to deliver a quality product that results in high customer satisfaction, developers need the right
technology and an effective methodology. Due to consistent project failures with traditional methodologies,
agile methods evolved to address the limitations of the traditional approach.
agile methoDS for riaS
Agile methods require frequent collaboration and embrace change. The product is developed iteratively in
short increments by tackling top priority features first. This enables earlier product delivery, which increases
return on investment (ROI) and allows the customer to provide feedback. In order to achieve these benefits,
supporting technology must be chosen. The technology must enable rapid development while providing
the flexibility necessary to adapt to constantly changing requirements. Technology plays a critical role in
achieving agility.
the role of technology in agility
Choosing a framework that fails to complement the fast-paced environment of an agile project can cripple
the development team. Rapid application development (RAD) tools and the ability to adapt to constantly
changing requirements are vital to meeting the demanding needs of an agile project.
RAD frameworks must provide a platform that allows the development team to focus on the business
problem. Non-functional requirements, including security, usability, performance, and scalability should
be achievable without significant impact to the application. As the needs of the application change in an
evolving business environment, the framework must provide the support necessary to adapt. JBoss
a web application framework, provides the perfect technology fit for an agile development environment.
achieving agility with JBoSS Seam
To demonstrate the value of using JBoss Seam in agile development, we will describe a series of use cases
for which JBoss Seam is applicable. Typical use cases encountered in enterprise application development
will be provided. We will then discuss and demonstrate the rapid implementation of each use case utilizing
the features provided by JBoss Seam. The use cases are derived from real experiences in the software field
and provide practical application of JBoss Seam.
Developing the initial pRoDuct
One of the tenets of agility is, “Release early, release often.” The early visibility of a software product often
plays a large role in the project's success. RAD tools allow a development team to get the project started
with minimal delay making them the ideal choice for putting this principle into action.
Seam-gen is the RAD tool packaged within JBoss Seam. This tool helps development teams generate
application “scaffolding.” Scaffolding is the boiler-plate code and configuration that is required by any
framework to plug into the capabilities that the framework provides. Once generated, a developer can
immediately focus on implementing the specifics of business features.
JBoss Seam: Agile RIA Development Framework
www.jboss.com 3
uSe caSe: get the proJect StarteD quickly with Seam-gen
The business wants to avoid a long ramp-up time for its new software product. In the past, the IT team
spent several months in the requirements and design phases prior to implementation. The initial demo
of the software product was often many months or even years after project kickoff. This time around,
the business would like to see a tangible product quickly so that it can be influential early in the process.
Seam-gen allows developers to create a project in minutes. The generated project is ready to be opened
in any leading Java IDE and ready to be deployed to an application server of your choosing. Seam-gen is
simple to operate and is ready for execution immediately after downloading JBoss Seam. After starting
seam-gen from the command line, the tool will ask several questions to configure the new project. The
questions are common to any enterprise application and address a range of concerns, including the project
name, selecting the front-end technology, and specifying the type of database for the application. Once the
questionnaire is complete, the project is generated in a matter of seconds complete with an Ant build file,
template webpages, seam resource files, and the necessary jars.
Seam-gen essentially alleviates the hassle of piecing together the build, configuration, and jar dependen-
cies. The project is ready for deployment and custom code can now be incorporated. This provides the initial
structure necessary to quickly release the application to the business for early feedback, and reduces the
work of the software team. With such early visibility to the business, the software team is braced to accom-
modate the business and address its needs.
uSe caSe: creating a cruD application with JBoSS Seam
The business wants to manage business data using a software application. Users want a web interface
to perform basic operations on the data. They would like a search screen to retrieve and view data. They
also want to create new entries, edit existing entries, and delete entries that are no longer needed. These
requirements are often referred to as a CRUD application (create, read, update, and delete).
Seam-gen offers an interface that allows developers to leverage the Seam Application Framework, a group
of components created to reduce the amount of custom code written when performing basic database
operations within a web application.
FiguRe 1
Get project
started quickly
Create CRUD
Reverse engineer
JBoss Seam Developer
JBoss Seam: Agile RIA Development Framework
4 www.jboss.com
The Seam Application Framework consists of two main components: EntityHome and EntityQuery.
The EntityHome object performs persist, remove, and update operations on a JPA entity. Essentially
the EntityHome object is a generic Data Access Object (DAO) that supports CRUD operations. The
EntityQuery object encapsulates a search query and offers methods to retrieve the data. It also allows
for customized search criteria and scrolling, which are common search page requirements.
Seam-gen can create EntityHome and EntityQuery objects for all JPA entities within an application.
In addition, seam-gen will generate basic front-end pages for browsing, searching, and managing applica-
tion data. Once the components have been generated through seam-gen, further customization can be
performed through configuration or class extension. The simplicity and automation offered by JBoss Seam
allows a software team to meet CRUD application requirements rapidly.
uSe caSe: application generation from an exiSting DataBaSe
The business has an existing database that now requires a web front-end. In the past, database administra-
tors have been responsible for managing the data. In order to reduce cost and turnaround time, the business
now wants to manage this data directly through a web interface.
Seam-gen can scan an existing database and generate an application from the existing schema. This capa-
bility is useful when a legacy database exists, but has no application built around it. Through the command-
line interface, seam-gen asks for the database specifics such as the JDBC URL, username, and password.
Most importantly, it asks for the schema name and if the application will work with tables that already exist.
If tables exist, JBoss Seam will read the database and generate JPA entities from the existing tables. The
entities are complete with mapped relationships and validation annotations. In minutes, a web application
is generated that supports legacy data management.
uSe caSe: generate ScaffolDing through a gui with JBoSS Developer StuDio
The development team prefers working within an IDE to executing commands in a shell window. JBoss
Developer Studio is an Eclipse-based integrated development environment that provides developers with
everything needed to rapidly build applications with JBoss Seam. A development team can achieve the
above uses cases (new project generation, creating a CRUD application, and application generation from
an existing database) through the JBoss Developer Studio user interfaces in lieu of seam-gen. In addition,
JBoss Developer Studio includes both tooling and runtime components that integrate with a large set of
JBoss open source technologies such as JBoss Seam, JBoss Hibernate, JBoss Application Server, and
JBoss jBPM — just to name a few.
secuRing the application FoR Release
The goal of any agile project is to release the application as quickly as possible. Once the application includes
a sufficient feature set to serve a business need, the software product can be released to the end users.
This goal achieves the quickest ROI for the application and further improves the end product by eliciting
feedback. To achieve agility, a team minimizes upfront design and focuses on the highest priority business
features first. Even with the importance of security in today's enterprise environment, it is rare for security
to be at the top of the initial priority list.
JBoss Seam: Agile RIA Development Framework
www.jboss.com 5
Security is an unspoken non-functional requirement that end users simply expect, similar to good perfor-
mance and ease-of-use. The development team may progress through several iterations before appropriate
consideration is given to application security. The product may even be ready for release before security is
considered. With this in mind, it is important to select a framework that allows these types of architectural
decisions to be delayed even up to the last minute without impacting the application.
JBoss Seam security embraces the agile mindset by implementing security as a cross-cutting concern.
This allows security features to be addressed when needed, even just prior to release, without a significant
effort. JBoss Seam security eliminates the complexities of enterprise security and allows you to iteratively
introduce your security needs into the application.
iDentify the uSer with JBoSS Seam Security
Determining the user's identity is the core of any security model. Once the user's identity is known, more
complex authorization requirements can be addressed. As shown in the diagram below, it is critical to
identify a user prior to allowing access to certain functions to avoid malicious access. The following use
cases demonstrate how JBoss Seam security allows an application to introduce authentication capabilities
iteratively in an application.
FiguRe 2
Search parts
JBoss Seam security
Edit part
Unknown user
uSe caSe: authenticate pre-proDuction uSerS
The business initiates the project with a small user base that will evaluate the in-progress product. The basic
authentication capabilities provided by a seam-gen project suit the needs of the in-progress product. In the
early stages of development, the user's identity may need to be determined in order to implement authoriza-
tion features, but in the early stages of evaluation an enterprise authentication method is often unnecessary.
Seam-gen projects provide a simple login form with an authenticator component for custom authentication
logic. You can add the logic necessary to authenticate the user and add any roles to the user's Identity. This
solution provides a rapid authentication approach but maintains the flexibility to adapt more robust enter-
prise security requirements by utilizing the Identity Management API.
JBoss Seam: Agile RIA Development Framework
6 www.jboss.com
uSe caSe: authenticate uSerS with an enterpriSe iDentity Store
The application is ready for production release but the organization requires that the application authen-
ticate through a centralized identity management solution (like Active Directory). While this is ideal for
managing a large user base, it often requires glue code to incorporate the specifics of the centralized
authentication mechanism. Fortunately, JBoss Seam security provides IdentityStore components out-
of-the-box that allow an application to authenticate against a relational database or an LDAP identity store
with minimal development effort.
If the centralized identity store is a relational database, JBoss Seam security utilizes the JpaIdentityStore
component along with the identity annotations. These annotations allow you to easily hook your existing
database schema directly into JBoss Seam security with JPA entity mappings for users and their roles. The
LdapIdentityStore allows users and roles to be retrieved from an LDAP directory by simply configuring
this component with the appropriate server details. By implementing your own IdentityStore compo-
nent you can integrate JBoss Seam security with any identity store technology (for example, Kerberos). In
addition, separate IdentityStore implementations can be used to authenticate the user and retrieve user
roles providing ultimate flexibility in retrieving the user's identity.
While this is an ideal approach to managing a production user base, a centralized identity store may not
be available. The next use case demonstrates how JBoss Seam security makes even the most complex
case simple through its Identity Management API.
uSe caSe: authenticate uSerS anD manage their iDentity
The organization does not have a centralized identity store, so we need a way to manage the production user
base efficiently. Maintaining a production user base can be a full-time job, but JBoss Seam allows you to put
this task in the user's hands through its Identity Management API. Seam-gen provides a rapid solution with
the add-identity-management command. This command can be executed for a new or existing seam-gen
project. This command integrates a front-end with the components, views, and configuration necessary to
manage users and roles using JBoss Seam's Identity Management API. Upon execution, a user interface is
generated for performing create, read, update, and delete (CRUD) operations on user and role information.
authorize the uSer for privilegeD acceSS
Most enterprise applications require distinction between application users to determine what privileged
operations a user has access to. The following diagram illustrates a simple case where only admin users
are able to manage users.
FiguRe 3
Search parts
Manage users
Edit part
JBoss Seam security
User Admin
JBoss Seam: Agile RIA Development Framework
www.jboss.com 7
In most applications, adding this type of functionality later leads to major changes in the code and and can
cause release delays. This is not the case with JBoss Seam. JBoss Seam security combines a declarative
access control with a unified approach to defining constraints, which creates a simple and flexible autho-
rization model. In addition, JBoss Seam security provides layered access control, which makes it simple to
enforce a defense-in-depth approach in your application. As you will see in the following examples, the use
of XML, annotations, and the unified EL makes authorization with JBoss Seam simple and provides the flex-
ibility to adapt your authorization capabilities as requirements demand.
uSe caSe: role-BaSeD acceSS to Specific application functionS
In the initial release, users are grouped together based on roles that govern who can perform what opera-
tion. JBoss Seam security provides the ability to authorize users according to the roles they have been
granted. Page access, user interface (UI) component access, and even JBoss Seam component access can
be restricted to a specific role through declarative access control.
Pages are defined in the pages.xml file, which allows you to restrict access to specific pages or sections of
the application through simple URL patterns and EL expressions. UI components can be hidden for certain
users by defining the role required in the components rendered attribute through EL. Method access can be
restricted through annotations on JBoss Seam components. Component annotations provide the option to
use EL restrictions to maintain ultimate flexibility or type-safe role annotations. Type-safe role annotations
provide the advantage of compile-time checks on component security constraints.
uSe caSe: application acceSS DetermineD By more than roleS
As the applications evolves, the complexity of authorization requirements increases. What used to be a
simple role check now requires a role check, a certain part type, and a specific part status. While this seems
complex, JBoss Seam provides the features necessary to address these capabilities through its permission
authorization model. The permission authorization model provides two implementations out-of-the-box, a
RuleBasedPermissionResolver and a PersistentPermissionResolver.
The RuleBasedPermissionResolver allows permissions to be evaluated through rules defined in
JBoss Rules. A set of rules defining a permission can be evaluated through a simple EL expression. This
allows previously defined restrictions to be easily adapted to the new permission resolution method.
The PersistentPermissionResolver allows permissions to be loaded from a relational database or
another persistent storage method.
This permission resolver allows specific permissions to be assigned to individual users and roles. For
example, a single user could be granted temporary access to edit a product type outside of his or her
normal permissions. A front-end can even be provided to easily alter persistent permissions through
the permission management API.
SecureD anD reaDy for releaSe
JBoss Seam security makes it simple to secure an application at every stage of development. Whether your
application is in the initial stages of development, requires LDAP authentication and role-based access, or
even requires complex ACL permissioning, JBoss Seam provides the flexibility necessary to achieve your
needs. In line with the iterative methods of today's agile development, JBoss Seam allows you to integrate
the security features you need, when you need them.
JBoss Seam: Agile RIA Development Framework
8 www.jboss.com
simpliFying the pRogRamming moDel
minimize architectural layering
The JBoss Seam programming model addresses the issues of complicated layering that occur in traditional
enterprise applications. These applications have many components, such as transactional services, security,
data persistence, object mapping, UI rendering, and more. Enterprise web applications typically need a
multi-tiered architecture, as this promotes separation of concerns, a model-view-controller pattern, and the
cohesion of responsibility within layers. JBoss Seam addresses these enterprise concerns while considerably
reducing layering.
uSe caSe: reDuce Development turnarounD time By Simplifying architecture
The client has noticed that what initially seems like a simple change request often turns into a complicated
problem on the technical side. The development team attributes this phenomenon to the complex architec-
tural layering of the system. Developers have to create excessive plumbing code to add new functionality
or spend time digging through the layers to determine where to make the appropriate code change. This
dramatically impacts the efficiency of the development team.
The Java EE technology stack (JSF, Enterprise Java Beans (EJB), JPA) used to implement enterprise
concerns is designed as separate frameworks. This disparity creates several unnecessary layers. For
example, the front-end layer is JSF and the business layer is composed of EJBs. But since the transactional
and persistence context is bonded to the EJB layer, a Data Transfer Object (DTO) layer is introduced to
display data on the front-end.
FiguRe 4
Backing bean
Transaction and persistence
context boundary
JBoss Seam simplifies layering, which reduces development time. JBoss Seam collapses the artificial layer
between EJB and JSF by allowing business components to directly back web forms and handle UI events.
JBoss Seam also extends the transaction and persistence context over the entire web interaction request
cycle so the Object Relational Mapping (ORM) objects can be accessed directly by the presentation layer.
This eliminates backing beans and DTOs.
JBoss Seam: Agile RIA Development Framework
www.jboss.com 9
FiguRe 5
Transaction and persistence
context boundary
Using a declarative annotation-based approach, JBoss Seam integrates the disparate enterprise frame-
works to minimize architectural layering. Developers are able to better understand the architecture and
can navigate the code without encountering unnecessary layers. This results in faster turnaround time
for change requests and a happier customer.
Simplify State management with converSationS
Lean principals are an important aspect of agile methods. Maximizing the work not done is critical to
eliminating waste. Conversations fit this bill perfectly by filling a gap in the traditional stateful web develop-
ment model. Traditional stateful web applications store all states in a shared state container: the session.
While this approach is simple, it leads to a lot of issues that are not immediately obvious. JBoss Seam breaks
each stateful interaction with the user into a separate conversation which is a unique state container. As
you can see in the diagram below, each browser window the user opens will initiate a new conversation.
The following use cases demonstrate how this model reduces development effort and immediately provides
user-friendly features.
FiguRe 6
JBoss Seam: Agile RIA Development Framework
10 www.jboss.com
uSe caSe: multi-winDow operation anD Back-Button Support
When business users run the application, they expect the browser's back button to behave consistently —
not matter how many windows or tabs they have open. Editing parts, booking vacation options, and config-
uring computers all require maintaining several pieces of information. The state of the user interaction
must be maintained across multiple page requests. Traditional web applications rely on the session, where
state is maintained in a single user state container. Each time a part is being edited, a vacation booked,
or a computer configured, previous state information is overwritten. This creates unpredictable behavior
when multiple windows are opened or the user backs up to a previous state.
With JBoss Seam, each time a user initiates a stateful interaction, a conversation is started. Each conver-
sation is a separate state container meaning that each stateful interaction is independent of the others.
In a JBoss Seam application, it is common for a user to have several conversations executing concurrently.
Conversations are started by simply specifying the conversation boundaries, defining where the conversa-
tion begins and ends.
A conversation can be associated to a single page or a set of pages in pages.xml, through the <begin-
conversation> and <end-conversation> elements. Even a set of method calls can define the conver-
sation boundaries by simply annotating methods with @Begin and @End. The session simply holds these
conversations with unique identifiers, allowing JBoss Seam to retrieve them according to which window or
tab the user is accessing (or the back-button destination). This allows users to interact with the application
naturally and prevents developers from needing to impose awkward navigation requirements.
uSe caSe: eliminate memory leakS anD reDuce Server memory requirementS
Previous applications have suffered from hard-to-debug memory leaks and have required extensive server
memory. Resolving these types of issues takes time away from implementing new business features and
creates a bad impression with business users. These issues often stem from storing state in the session.
As the user navigates through stateful interactions with the application, the session data grows indefinitely.
Without careful programming, state information is stored until a session timeout. As the number of users
grows, the problem becomes exponentially worse.
Using JBoss Seam conversations ensures that state information is managed properly. Stale information is
automatically cleaned up when it is no longer needed. By maintaining each stateful interaction in a separate
conversation, JBoss Seam can apply a timeout to the state. Once a conversation has been out-of-use for a
configured period of time, JBoss Seam will remove the conversation. This ensures that regardless of appli-
cation usage patterns, state information will consistently be cleaned up with no additional effort from the
development team.
looSe coupling with DepenDency BiJection
Enterprise applications that are difficult to maintain are generally plagued by tight coupling. Small changes
impact seemingly unrelated components due to tightly woven dependencies. These brittle systems have
a negative effect on team velocity. By contrast, loose coupling ensures that application components are
largely independent. The impact of change is generally limited to a single component that reduces effort.
Loose coupling is achieved through dependency injection in modern-day frameworks.
Dependency injection is the inversion of the control technique where dependencies are injected by a
container. An injected dependency can be a single object or a group of objects working together to achieve
some goal. These components define a contract of interaction through their APIs. This ensures that as long
as the contract is upheld, the component can change independently. Bijection is JBoss Seam's flavor of
dependency injection. As shown in the diagram below, components are injected from the context.
JBoss Seam: Agile RIA Development Framework
www.jboss.com 11
Context is important in bijection. Components can be injected as dependencies or outjected into the context,
making them available to other components. The following use cases demonstrate the simplicity of imple-
menting complex application requirements using bijection.
uSe caSe: Swap the implementation when requirementS change
The business originally calculated shipping fees based on internally defined costs, but now wants to calcu-
late shipping fees based on external shipping company costs. All shipping calculation logic now needs to be
modified to call the business' external APIs. If the shipping calculation logic was spread throughout the appli-
cation, this would require extensive changes to the application. Bijection resolves this by providing a mecha-
nism to hide this complexity behind an interface that defines the contract of interaction.
By implementing logic behind an interface, it is simple to change the implementation. Each component is
given a name and is injected by that name. To alter the implementation, simply develop the new component
according to the existing interface, and replace the existing component by name. The new component will be
injected to replace the existing component in all places. Application behavior is immediately altered through
a change in a single location.
uSe caSe: initialize common oBJectS only once
User profile information is needed throughout the application to perform business functions. Generally
this type of common data is retrieved when needed by direct database retrieval or by calling on a data
access object (DAO). This approach is often inconsistent, making it difficult to change the way these
objects are retrieved. Bijection allows you to provide a single location where these objects are initialized.
Once outjected into the context, objects can be injected by name into any component.
Factory methods allow you to define a single location where an object is initialized and set into the context.
Simply annotate a method with @Factory to create a factory method. As with a component, the factory
method gives a unique name to the object so it can be referenced. When being requested by name through
EL or by a component as a dependency, the factory method is invoked and the object is initialized. This
provides a single location for changing the way an object is retrieved and makes accessing the object simple
for any JBoss Seam component.
FiguRe 7
Before you begin, here is the
shippingService to use...
JBoss Seam: Agile RIA Development Framework
12 www.jboss.com
proDuction-reaDy coDe the firSt time with JBoSS Seam teSt
Agile teams value testing to ensure quality of their products. Agile developers utilize Test Driven
Development (TDD) techniques to specify behavior, guide design, and validate correctness of code. TDD
enables the developer to iteratively produce quality code, while at the same time increasing productivity.
Refactoring can occur due to the safety net of a regression test suite.
JBoss Seam supports the agile testing paradigm with SeamTest, a testing framework for JBoss Seam appli-
cations. JBoss Seam is a plain-old Java object (POJO)-based framework, which makes it ideal for unit testing.
SeamTest includes support for unit testing with mocks, as well as integration testing for full functional vali-
dation of a system.
uSe caSe: eliminate DefectS early with unit teSting uSing SeamteSt
A consistently high number of defects is found during user testing. The cost of defects caught late in the
development cycle is very high. The production release is delayed by new bugs introduced by last-minute
fixes. This leads to production downtime. The development team aims to build a unit test suite to address
this obvious quality issue.
Unit testing, in conjuction with TDD, validates code incrementally and catches defects early in the process.
When a bug is eliminated early, less cost is incurred. In order to make unit testing easy, JBoss Seam provides
SeamTest, which is based on the TestNG framework. TestNG is a next-generation test framework inspired by
JUnit. It contains a host of useful features such as support for all categories of testing (unit, functional, and
integration), parallel test execution, and configuration-based grouping of tests.
As JBoss Seam components are POJO-based and leverage bijection, testing is as simple as setting attribute
values and invoking the method under test. In certain circumstantances creating a unit test requires mocking
out class dependencies that are bijected. SeamTest provides the mock facilities to simulate bijection.
In addition, developers can test database-dependent modules by mocking out the database. JBoss Seam
comes bundled with HSQLDB, a hypersonic database often used to replace a production database in a
testing environment. By configuring the persistence.xml to connect to HSQLDB, you can test out JBoss
Seam components with a mock database.
uSe caSe: valiDate the SyStem with automateD integration teStS
The business would like to reduce the drag of manual end-to-end testing prior to release. Repeating manual
regression tests of existing features is time-intensive and high-cost. However, the risk of dropping this
testing entirely is too high. The development team makes an effort to write automated integration tests to
address this concern.
Integration testing can pose technical challenges, as application components generally depend on container
infrastructure. This infrastructure is only available when the application is deployed to the application
server. Automated testing of deployed applications is achievable, but requires additional tools and overhead.
SeamTest alleviates this hurdle by providing an embedded runtime environment that manages JBoss Seam
components. The embedded environment provides the necessary container services to emulate the server
environment. Developers can test JBoss Seam components, trusting that they'll behave just as they would
when deployed to the application server.
In order to exercise functional tests, execution can be started from the JSF layer. SeamTest is able to bind
test data to JBoss Seam components via JSF EL expressions, as well as invoke component actions. The
FacesRequest API allows you to manipulate the JSF lifecyle to simulate different scenarios. JBoss Seam
can also mock out resources that are not available in the integration test environment with the annotation
JBoss Seam: Agile RIA Development Framework
www.jboss.com 13
@Install(precendence=MOCK). For example, the JBoss Seam identity component, which models a live
user, can be mocked out in the test environment with a substitube mock class with the @Install annota-
tion. With these tools at hand, a developer can create an integration test that closely resembles a JSF page,
invokes JBoss Seam components, and executes all the way to completion.
SeamTest provides the tools necessary to create a valuable regression test suite. Agile teams rely on testing
to produce a quality product. JBoss Seam provides the infrastracture to make testing an everyday practice.
ReDuce FRont-enD Development eFFoRt
with JBoss seam
User interface design and implementation plays a large role in enterprise web application development. The
user interface provides the first impression of an application and is often linked to the success of a project.
UI implementation techniques also affect success. Agile developers value simplicity, maintainability, and
flexibility when choosing a front-end technology.
front-enD freeDom of choice
JBoss Seam is UI-agnostic — it allows you to choose the RIA technology that is the right fit for your project.
JBoss Seam greatly simplifies JSF development, but also provides many front-end technologies to choose
from. This gives developers maximum flexibility in user interface development.
uSe caSe: interface muSt aDapt to conStantly changing client neeDS
The business has basic application needs today, but anticipates that external applications will likely require
complex desktop-like features, interface animation, and mobile device access sometime in the future. JBoss
Seam is web 2.0-ready with a host of features that simplify front-end development regardless of what RIA
technology the features necessitate. JBoss Seam POJO components remain independent of the view layer,
allowing the interface to adapt to changing client needs.
JBoss Seam comes packaged with RichFaces, a component library for JSF that makes it simple to incorpo-
rate AJAX-enabled components into your application. IceFaces, an alternative JSF component library, also
enables simple AJAX out-of-the-box. JBoss Seam also includes various integration APIs that connect other
view technologies. Flamingo can be used to glue Flex, JavaFX, Swing, J2ME, or Android to Seam. Seam also
provides an integration layer for the Google Web Toolkit (GWT) that allows GWT widgets to interact directly
with Seam components.
Dry up your JSf with faceletS
By default, JBoss Seam integrates with Facelets as its view technology. Facelets technology was designed
to align with the JSF component model and lifecycle — as opposed to JSP technology which places focus
on generating dynamic content. Unlike JSPs, Facelets artifacts are not compiled into Servlets. Facelets are
defined as .xhtml files and are directly transformed into elements of the JSF component tree.
Facelets technology boasts a simple programming model, higher performance rendering, and better lever-
ages JSF. The diagram below depicts how the core Facelets features of templating and composite compo-
nents enable reuse across JSF pages. An application may have three separate pages, but each page shares
a page template while two of the pages display a common component.
JBoss Seam: Agile RIA Development Framework
14 www.jboss.com
The following use cases describe how these features enable rapid JSF development by adhering to the agile
principal "don't repeat yourself" (DRY).
uSe caSe: maintain a conSiStent look anD feel acroSS pageS
The business wants every page of the application to have a standard menu at the top and a footer at the
bottom to maintain a consistent look and feel. Templating allows you to create pages that act as a base
for other pages in an application. Using the ui:composition tag and the template attribute, developers
can build a file that contains header and footer information and then create content pages that inherit their
appearance from the template file.
The template is specified with ui:insert tags, which identify where page content can vary. Templated
pages then use ui:define tags to define exactly how the content should vary. This applies the Gang of Four
(GoF) template method pattern to UI pages. Templating allows JBoss Seam developers to develop new pages
rapidly with a consistent look and feel by reusing code.
View product
Edit product
Product sales
FiguRe 8
JBoss Seam: Agile RIA Development Framework
www.jboss.com 15
uSe caSe: reDuce ui coDe uSing compoSite componentS
The business needs to display summary information of the common business data in various locations
throughout the application. The summary information is composed of several JSF components, including
a data table, chart, and tree. The brute force approach to solving the above use case would be to repeat
the JSF tag code in every page of the application. However, this would result in a large amount of duplicated
code and would violate the DRY principle. Adhering to DRY is critical to developing reusable and maintain-
able code.
Facelets technology offers composite components. A composite component is one or more existing JSF
components that are used together. Any markup within an .xhtml file can be used to create a composite
component. Unlike a traditional JSF custom component, a composite component does not require the
implementation of complicated JSF interfaces or custom rendering of objects.
By extracting JSF component declarations into a .xhtml file, then passing the parameters to the page,
a developer can create a custom component. This file can then be defined as a custom tag by simply refer-
encing the file and giving it a name. The custom tag can now be easily imported and used across pages.
Each page can pass specific parameters to customize the component according to business rules. This
allows a single declaration of the JSF UI components, while enabling the content to vary per page.
rapiD aJax Development with richfaceS
RIA applications are often appealing because of their positive user experience. The UI is quick and respon-
sive and the application feels more like a desktop application. A key component that facilitates this rich
user experience is Ajax. With the arrival of web 2.0 applications, Ajax has moved into the spotlight.
However, implementing Ajax capabilities has its consequences. Client-side scripting development is lengthy
and code testing is arduous. Managing asynchronous requests and browser compatibility with scripting code
are problematic issues. These concerns increase the development time for a team and can hinder the agility
of a project.
RichFaces is an Ajax-enabled framework that allows easy integration of Ajax capabilities into a web applica-
tion. Developers can integrate Ajax capabilities and applications, without using JavaScript. Any RichFaces
component can be Ajax-enabled, making development of an RIA application very easy.
uSe caSe: enhance uSer experience with richfaceS componentS
The business wants a web application that is slick, visually appealing, and demonstrates user interaction —
unlike the click and wait applications of the past. The development team wants to provide these capabilities
without affecting project velocity. RichFaces is able to meet this need quickly and efficiently.
The RichFaces component library comes with a large set of packaged components from which developers
can choose. You can use components prefixed with rich: — which are Ajax enabled out of the box — or use
a4j: components that add Ajax capabilities to standard JSF components. RichFaces also allows page-wide
support so that portions of a page can be updated with Ajax requests, thus limiting form submission to the
server. Ajax capabilities and concerns are taken care of by the RichFaces framework, greatly easing the
burden to the developer.
In addition, JBoss Seam simplifies the use of Ajax, making it the perfect pairing for RichFaces. The asyn-
cronous requests Ajax introduces can create concurrency issues in stateful web applications. JBoss Seam
automatically synchronizes the conversation, which ensures that even in the face of asynchronous requests,
applications behave consistently.
JBoss Seam: Agile RIA Development Framework
16 www.jboss.com
integRation FRamewoRk
Enterprise applications often require a host of various technologies to fulfill complicated requirements.
For example, an application may need to export a document as a PDF file or send a daily report to users by
email. A work-flow engine could be used to coordinate several different collaborating enterprise applications.
JBoss Seam is a powerful framework that integrates various technologies so that developers can quickly
meet business needs. JBoss Seam developers interact with simplified APIs and use a consistent declarative
approach to leverage various technologies.
uSe caSe: SenD a Daily report to uSerS
The business would like a summary report of sales data delivered daily by email. At a specific time of day,
the application must assemble summary data in an email and deliver it to the users' email boxes. Sending
email from a web application is not complicated, but it is a messy task. The developer must navigate his
way through the JavaMail API and embed data as string literals, while formatting the mail with HTML tags.
The procedure is error-prone and painful.
JBoss Seam simplifies email generation with a template-based approach. The email format and content
is developed as an .xhtml file. JBoss Seam provides mail tags that can be placed directly into a page.
For example, <m:from>, <m:to>, and <m:subject> mark the typical portions of an email message. JBoss
Seam components then use Renderer to send the template out as an email. Because the message is devel-
oped as a Facelets page, the API is powerful and familiar to the developer, allowing complex messages to
be created easily.
In order to satisfy the requirement of delivering email at a specific time of day, JBoss Seam utilizes Quartz
Scheduler. Quartz is an open source implementation built to handle recurring tasks in applications. You
can use annotations to mark a method that needs to execute periodically. The @Asynchronous annotation
marks the periodic method, while the @Expiration, @IntervalDuration, and @FinalExpiration annota-
tions delineate the timing aspects of the task. The declarative nature of annotations with Quartz provides a
simplistic alternative to the conventional code-heavy timer APIs of Java Timer and EJBTimer.
uSe caSe: orcheStrate DiSparate applicationS into one BuSineSS proceSS
The business has several existing applications that function separately, but together achieve a business goal.
For example, an insurance agency has one application that files a claim, then another application that evalu-
ates the claim, then yet another that processes the claim. The communication between these steps is done
manually by employees. It would be beneficial if this business process was automated.
JBoss Seam comes integrated with JBoss jBPM (Business Process Management). JBoss jBPM helps enter-
prises create and automate business processes that coordinate between people, applications, and services.
jBPM offers workflow capabilities, process management, and state management that can be harnessed to
define business flows in a fast and efficient manner, while reducing development time.
Instead of manually coding coordination between systems, JBoss jPBM allows a declarative approach to
define process in a centralized place. JBoss jPDL (Process Definition Language) uses declarative program-
ming techniques and allows developers to simply structure processes. The JBoss visual jPDL IDE designer
further eases process design, as the developer can define the process in a UML-like syntax. Furthermore,
all the useful attributes of JBoss Seam, including stateful components, JSF, Ajax, and JBoss Hibernate,
are fully available during JBoss jBPM development.
JBoss Seam: Agile RIA Development Framework
www.jboss.com 17
Using JBoss jPDL, a developer can integrate business process state definition with a UI pageflow sequence.
JBoss jPBM integration removes much of the overhead encountered when developing automated business
process management applications. The focus can remain on increasing the business value instead of tech-
nical hurdles.
uSe caSe: uSe exiSting Spring BeanS in a JBoSS Seam application
The business has an older application that contains functionality now needed for the new flagship devel-
opment project. The application was developed using the Spring framework, so the development team is
looking to re-use existing Spring beans. This allows the team to focus on new feature development rather
than recreating existing solutions.
JBoss Seam makes it simple to utilize existing Spring beans within JBoss Seam components. By simply
adding the Spring DelegatingVariableResolver to the faces-config.xml file, any Spring bean can
be injected or accessed in an XHTML page via EL. If you are not using JSF or you would prefer your Spring
beans to be JBoss Seam components, you can simply place the <seam:component> tag within the bean
wealth of Supporting technologieS
iText PDF generation, Seam Mail, Quartz Scheduler, and JBoss jBPM are some of the more notable tech-
nologies that are smoothly integrated into JBoss Seam. Below is a table containing some of the integration
technologies that JBoss Seam provides.
technology DescRiption
iText PDF generation
JBoss jBPM Enterprise business process management
Seam Mail Email distribution
Quartz Scheduler Schedule recurring tasks
Spring Framework Dependency injection framework
ANTLR Rich text and WYSIWYG output
Drools Business rules engine
Groovy Dynamic language capabilities
TestNg Unit testing framework
Microsoft Excel Spreadsheet Application Export of information into Excel files
YARFRAW RSS feed integration
CAPTCHA Distinguish between human and automated interactions
JBoss Seam: Agile RIA Development Framework
18 www.jboss.com
scaling on a Dime with JBoss seam
Enterprise application scalability is critical in today's rapidly changing business environment. User bases
grow quickly as new applications and websites gain popularity. The rapid pace of adoption is an exciting
prospect, but even the best applications are rendered useless when their load capabilities are exceeded.
The database is generally the primary performance bottleneck. The database is often shared across appli-
cation instances in a clustered environment and even across different applications. Expensive and repeated
calculations also hinder performance by utilizing precious CPU time. The multi-layer caching provided by
JBoss Seam eliminates bottlenecks at the source and enhances performance with minimal impact to the
underlying application logic. As shown in the diagram below, caching can be performed at the presentation
layer, business layer, and ORM layer with JBoss Seam allowing you to address caching according to the
specifics of a scenario.
FiguRe 9
View product info
View sales trends
Ship product
Presentation layer
Business layer
ORM layer
2nd level cache
JBoss Seam multi-layer caching
Enabling multi-layer caching is easy. JBoss Seam supports three cache providers out-of-the-box: JBoss
Cache, JBoss POJO Cache, and EHCache. Simply include the caching library along with its dependencies
and configure the cache provider in the components.xml file. As each use case will demonstrate, multi-
layer caching allows the application to scale according to user needs without affecting the team's ability
to deliver new features.
uSe caSe: renDering Static weBpageS
The business has several product information pages that change rarely. These pages are rendered by
querying the database, loading a hierarchy of entities, and then constructing the page from a component
tree. If certain pages are used often and change rarely, the processing time and memory spent rendering
these pages can be reclaimed. While this seems complex, JBoss Seam makes it simple.
JBoss Seam: Agile RIA Development Framework
www.jboss.com 19
The view caching provided by the multi-layer caching model addresses this issue. The <s:cache> compo-
nent wraps a set of JSF components in an XHTML page. This instructs JBoss Seam to cache this region
of HTML when rendered by JSF. Upon following page requests, JBoss Seam will then render the cached
portion of the page from memory until the configured time of expiration. This bypasses any database
calls, avoids reloading entities into memory, and saves processing time to re-render the page.
uSe caSe: retrieving Data that iS heavily uSeD anD reaD-moStly
The application regularly retrieves general product data for business functions. The data is read-only most
of the time. Since the page is frequently used, the queries to retrieve the data are repeatedly issued. It is
unnecessary to continually execute queries to retrieve this type of read-mostly data. With JBoss Hibernate
as the default ORM, second-level caching can be leveraged. Data can be cached in-memory to avoid a
database round-trip, which improves application performance and reduces database load.
JBoss Hibernate can cache read-mostly data by configuring a second-level cache provider. Simply enable
second-level caching, specify the cache provider, and annotate the entities that should be cached. When a
configured entity instance is first retrieved, JBoss Hibernate will issue a database query. Once loaded, the
entity data will be stored in-memory using the configured cache provider. On subsequent entity retrievals,
JBoss Hibernate will load the instance from the in-memory cache, thus bypassing the database altogether.
JBoss Hibernate will continue to use the cache until the configured expiration policy is exceeded.
uSe caSe: high-coSt calculationS that often yielD the Same reSult
The application performs CPU-intensive trending calculations for last month's sales.The sales team accesses
this information regularly to compare weekly sales figures and perform forecast analysis. As this informa-
tion is calculated a month at a time, performing this calculation on every request uses excessive CPU cycles.
To avoid this, calculations could be performed when first requested and the information cached for the
remainder of the month.
JBoss Seam provides direct access to the cache provider through the CacheProvider component. This
component can be injected into any JBoss Seam component and then used to cache any Java object. In this
case, the calculated results could be stored in a POJO and the object put into the cache. The object can then
be retrieved from the CacheProvider on subsequent requests to avoid additional calculation until the first
request of the next month.
agile Ria Development FRamewoRk
JBoss Seam simplifies development and places focus back on implementing business needs. This enables
agile teams to be successful in today's dynamic business environment. JBoss Seam provides the perfect
technology fit for the agile development environment.
JBoss Seam: Agile RIA Development Framework
Copyright © 2010 Red Hat, Inc. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix,
and RHCE are trademarks of Red Hat, Inc., registered in the U.S. and other countries. Linux
is the registered
trademark of Linus Torvalds in the U.S. and other countries.
JBoSS SaleS anD inquirieS
north america
europe, miDDle eaSt
anD africa
00800 7334 2835
aSia pacific
+65 6490 4200
latin america
+54 11 4341 6200
aBout reD hat
Red Hat was founded in 1993 and is headquartered in Raleigh, NC. Today, with more than 60 offices around
the world, Red Hat is the largest publicly traded technology company fully committed to open source. That
commitment has paid off over time, for us and our customers, proving the value of open source software
and establishing a viable business model built around the open source way. Red Hat provides high-quality,
affordable technology to the enterprise. Our solutions are delivered via subscription and range from oper-
ating systems and platforms like Red Hat Enterprise Linux and JBoss Enterprise Middleware, to application
and management tools, as well as consulting, training, and support.
aBout the authorS
Jacob orshalick is a software consultant, open source developer, and author. He is the owner of solutionsfit,
a consulting firm that provides agile software solutions to clients demanding the best that IT has to offer.
Jacob is actively involved in the JBoss community and is the co-author of "Seam Framework: Experience
the Evolution of Java EE."
nirav assar is an agile java consultant in the Dallas/Fort Worth, TX area. His expertise includes helping
software development teams adopt agile practices, as well as designing and implementing enterprise
applications using the principles of object oriented design and clean code.