Book Image

Apache MyFaces 1.2 Web Application Development

Book Image

Apache MyFaces 1.2 Web Application Development

Overview of this book

Hypes and trends (such as Web 2.0) cause a change in the requirements for user interfaces every now and then. While a lot of frameworks are capable of meeting those changing requirements, it often means you as a developer need in-depth knowledge of web standards, such as XHTML and JavaScript. A framework like Apache MyFaces that hides all details of how the page is rendered at the client and at the same time offers a rich set of tools and building blocks could save you a lot of time, not only when you're building a brand new application but also when you're adapting an existing application to meet new user interface requirements.This book will teach you everything you need to know to build appealing web interfaces with Apache MyFaces and maintain your code in a pragmatic way. It describes all the steps that are involved in building a user interface with Apache MyFaces. This includes building templates and composition components with Facelets, using all sorts of specialized components from the Tomahawk, Trinidad, and Tobago component sets and adding validation with MyFaces Extensions Validator.The book uses a step-by-step approach and contains a lot of tips based on experience of the MyFaces libraries in real-world projects. Throughout the book an example scenario is used to work towards a fully functional application when the book is finished.This step-by-step guide will help you to build a fully functional and powerful application.
Table of Contents (22 chapters)
Apache MyFaces 1.2
Credits
About the Author
Acknowledgement
About the Reviewers
Preface
Trinidad Tags
Trinidad Text Keys
Default JSF Error Messages
ExtVal Default Error Messages

Keeping the state of a component


Converter and validator components are part of the component tree of the view. This tree is recreated for every request. In other words, the tree lives in the request scope. A common problem in JSF is keeping the state of converters and validators or other components that live in the request scope. In Chapter 6, we created a custom converter that had a configurable separator property. This separator is part of the state of the converter and is needed in every request. Let’s see how we can adapt that converter to keep this state over multiple requests.

In order to be able to save the state, we have to implement the javax.faces.component.StateHolder interface, which involves implementing four methods. If we implement these methods, our example converter from Chapter 6 will now look as follows:

package inc.monsters.mias.conversion;
import javax.faces.component.StateHolder;
// other import omitted
public class FoodListConverter implements Converter,
ClientConverter...