HTML and CSS Reference
JSF2 Advanced Topics
This chapter is a collection of advanced topics that JSF application writers must take into consideration when writing
real-life JSF applications. We will also look at how to use the <f:ajax> tag to Ajaxify and improve the user experience.
build a real-world application without thorough testing. We will examine the Arquillian testing framework sponsored
by Red Hat through the JBoss Community.
Design Considerations for JSF Applications
This section highlights design considerations that you should take into account when building JSF applications.
We will touch upon the importance of minimizing usage of session data, how to approach security, where to save state
views, and finally managed bean scopes vs. CDI scopes.
Minimizing Use of Session-Scope
When developing JSF applications you should be particularly careful about using session-scoped beans. It may be
tempting to store objects in the user session, as it is conveniently available throughout the application. The problem
with this convenience is an increasing memory footprint per user. You may end up with large session objects that
are not collected until the user ends the session. This will put limits on the number of concurrent users because the
more users accessing the system the more physical memory is required for the application server, thereby making
the application non-scalable. Session-scoped objects should be used only for storing data that should live from the
beginning of a user session to the end. Common data that lives throughout a user session could be username, person
names, login time, and preferences. You should avoid using session-scoped objects for storing data about selected
objects in a master-detail or binary objects that may potentially be very big, such as a user profile picture. As a rule
of thumb, you should have only one session-scoped managed bean in your JSF application. Seriously consider the
architecture of your application if you feel the need for multiple session-scoped beans.
■ It is common for developers not to address application performance until the end of the software development lifecycle.
However, when you use session objects in JSF you must pay attention to performance testing and profiling of the application
early in the development process and throughout the whole process. It is particularly important to profile the memory footprint
while simulating multiple user sessions. There are many Java profiles available. We recommend that you use a profiler that
integrates well with your development environment to make it as easy as possible to profile your application during development.
If the profiler is slow and cumbersome to use, you will likely avoid using it and you will not discover scalability issues early
enough. Some IDEs have a built-in profiler that makes it easy to profile both memory and CPU consumption, as shown in
Figure 11-1 . To simulate multiple user sessions you can use an open-source tool like Apache jMeter ( http://jmeter.apache.org ),
where you can build a test plan that simulates multiple users by spawning multiple threads over a period of time.
Search WWH ::