使用Java Server Faces技术自定义组件
2008-01-05 09:35:38 来源:WEB开发网核心提示:CUSTOM COMPONENTS WITH javaSERVER FACES TECHNOLOGYThe March 24, 2004 Tech Tip ImPRoving Designs With the MVC Design Pattern introdUCed the architectural pattern
CUSTOM COMPONENTS WITH javaSERVER FACES TECHNOLOGY
The March 24, 2004 Tech Tip ImPRoving Designs With the MVC Design Pattern introdUCed the architectural pattern known as Model, View, Controller (MVC or Model2). MVC is a pervasive pattern throughout the world of computer science, and is fundamental to understanding JavaServer Faces (JSF) technology. The pattern separates the data and business logic of an application from its visual representation. The data and business logic is stored in an object called the Model. The visual representation is stored in a separate object called the View. The two objects are linked together with a third object called the Controller. The controller reacts to input from the view and updates the model data accordingly. The advantage of using this design is that any changes to the business logic or data can be isolated to the model without affecting the view. You can create multiple views without affecting the model.
A second tip in the March 24, 2004, titled Introducing JavaServer Faces Technology showed how to create a JSF application that includes GUI components that are modeled by the JSF framework. In this tip, you'll learn how to create custom components using JSF technology. More specifically, you'll learn how to create a custom JSF technology component that represents a simple stock display. Through an accompanying JavaServer Pages (jsp) page, a user can enter a stock symbol into a input text field and then press the Submit button. In response, the custom component displays a table below the text field. The table contains the stock's symbol, the current price of the stock, and the daily change in the stock price.
This tip assumes that you are familiar with the basics of JSF technology, and you know how to create JSP technology custom tag libraries. For information on the basics of JSF technology, see An Introduction to JavaServer Faces. For information on creating your own JSP custom tag libraries, see Using Custom Tags in the J2EE 1.4 Tutorial.
To create the custom component, you need to:
Create a JavaBean Model class that can be used to retrieve the stock data
Create a custom JSF View output component class that extends javax.faces.component.UIComponent.
Create a custom JSF View class that extends javax.faces.render.Renderer.
Integrate the custom component into the JSF framework using a custom tag.
Create a JSP page, including an input text field, and a backing bean for the input text field to assist the custom component.
Here is a visual representaion of how these objects fit in the MVC architecture.
更多精彩
赞助商链接