WEB开发网      婵犻潧鍊婚弲顐︽偟椤栨稓闄勯柦妯侯槸閻庤霉濠婂骸浜剧紒杈ㄥ笚閹峰懘鎮╅崹顐ゆ殸婵炴垶鎸撮崑鎾趁归悩鐑橆棄闁搞劌瀛╃粋宥夘敃閿濆柊锕傛煙鐎涙ê鐏f繝濠冨灴閹啴宕熼鍡╀紘婵炲濮惧Λ鍕叏閳哄懎绀夋繛鎴濈-楠炪垽鎮归崶褍妲婚柛銊ュ缁傚秹鏁撻敓锟� ---闂佹寧娲╅幏锟�
开发学院WEB开发Jsp 使用Java Server Faces技术自定义组件 阅读

使用Java Server Faces技术自定义组件

 2008-01-05 09:35:38 来源:WEB开发网 闂侀潧妫撮幏锟�闂佸憡鍨电换鎰版儍椤掑倵鍋撳☉娆嶄沪缂傚稄鎷�婵犫拃鍛粶闁靛洤娲ㄩ埀顒佺⊕閵囩偟绱為敓锟�闂侀潧妫撮幏锟�  闂佺ǹ绻楀▍鏇㈠极閻愬灚瀚梺鍨儏閳ь剙绉归弻銊р偓闈涙啞閻h京鈧敻鍋婇崰鏍х暦閿燂拷
核心提示: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.

Tags:使用 Java Server

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接