20.04.2013 Views

Practical RichFaces, Second Edition

Practical RichFaces, Second Edition

Practical RichFaces, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 1 THE BASICS<br />

As you can see, usually you won’t be working with HTML markup directly. You will simply use<br />

components that render the entire necessary markup.<br />

A note on rendering other markup languages. In the early days of JSF, the idea that components can<br />

render different markup based on client device was an interesting one. At that time, the mobile devices<br />

available usually worked with markup languages such as XML or WML. Today the situation is very<br />

different. Most modern mobiles devices, such as smart phones and tablets, come with powerful<br />

browsers supporting all the latest HTML, JavaScript, and CSS features. In some cases, the browser on a<br />

mobile device is better than the one on a PC. This means that generation markup other than HTML is no<br />

longer as important or has simply faded with the availability of mobile phones and other devices that<br />

support HTML.<br />

This doesn’t mean that renderers no longer play an important role. Even though HTML is now<br />

supported on various devices, renderers still play a role in regards to the kind of markup (HTML) that is<br />

generated. With the explosion of mobile devices, we now have to develop applications for a large<br />

number of different screen sizes. There is only so much “content” (or real estate) that can fit on a mobile<br />

phone with a 3.5-inch screen, or a tablet with a 7-inch screen, or even on a large laptop screen. This is<br />

exactly where renderers can help. Based on the device, screen size, and even screen resolution, the<br />

renderers can provide different markup.<br />

Events<br />

JSF takes you beyond the request/response paradigm and provides a powerful event-based model. The<br />

UI components that you use to build the user interface are sending events (when activated or clicked) to<br />

the server (browser events such as click are mapped to server-side component events). Listeners then<br />

process the events. For example, clicking a button (which is a UI component) is an event that is<br />

processed by an appropriate listener. (The JSF event-based model offers an approach to UI development<br />

similar to other user interface frameworks such as Swing and Flex.)<br />

For instance, in the #{simpleBean.save} expression defined in an action attribute, save is a<br />

method inside simpleBean bean. It is usually referred to as a JSF action and will be invoked when the<br />

button is clicked:<br />

<br />

Before we continue, you need to be familiar with the JSF life-cycle phases shown in Figure 1-5 and<br />

need to understand what each phase does. We will be using this same diagram to show <strong>RichFaces</strong><br />

concepts. Make sure you understand what each phase does and what happens to the flow in case of a<br />

conversion/validation error or when using the immediate="true" attribute. Understanding the life cycle<br />

can also help with debugging your JSF applications with phase listeners. You will be using a phase<br />

listener later in this book. In case you need to brush up on JSF phases, this article at Javabeat<br />

(www.javabeat.net/articles/54-request-processing-lifecycle-phases-in-jsf-1.html) is a good place<br />

to do that.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!