This chapter gently introduces the JavaServer Faces technology. More importantly, it teaches you how to write your first JSF application to get a feel for how this great technology works. In addition to the sample chapters, this chapter prepares you for the next chapters by introducing the JSF Application Programming Interface (API) and the Application Configuration file. This excerpt comes from chapter two of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983-7, 2004).
As noted earlier, you can bind a component to a JavaBean. In this case, the component’s local value will be copied to the JavaBean’s property if the local value is valid. To bind a component to a JavaBean’s property, you use the valueRef attribute in the custom tag representing the component. For example, to bind a UIOutput component so that it can retrieve its value from the result property of a JavaBean called testingBean, use the following:
Because JSF applications are event-driven, you need to write event listeners to determine how your applications will behave. You need to register any event listener that you want to be notified when an event is triggered by a component. To register an ActionListener with a component such as a UICommand, use the action_listener tag of the Core custom tag library inside the custom tag representing the component:
You must also write your listener class by implementing the javax.faces.event. ActionListener interface or the javax.faces.event.ValueChangedListener interfaces.
Events and listeners are discussed in more detail in Chapter 7.
Remember: This is part one of the second chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). Stay tuned for part 2 of "Introduction to JavaServer Faces," where we learn about JSP, JavaBeans, and Model 2. Buy this book!