Use a JSF architecture for Design

Source: Internet
Author: User
Use a JSF architecture for Design

Explore the design modes used in the assumerver faces framework

File Selection


<Tr valign = "TOP"> <TD width = "8"> </TD> <TD width = "16"> </ TD> <TD class = "small" width = "122"> <p> <SPAN class = "Ast"> the Javascript file selection cannot be used for display </span> </P> </TD> </tr>



Friendly Printing

Forward to this article


Others: Moderate

Anand Prakash Joshi, software engineering engineer, IBM

January 04, 2006

In this article, the author Anand Joshi uses the design mode in the JSF framework to parse the JavaServer faces (JSF) architecture. He commented on the gof design patterns used in the JSF architecture and their role in the JSF framework. Anyone who has some knowledge about the design mode and the JSF architecture can collect information from the Anand architecture introduction. * The author should have a good understanding of the gof design mode and JSF technology.

The design mode can help users abstract the architecture on a higher level and better understand the architecture. If you are more familiar with the gof design mode and the JavaServer faces (JSF) framework than parse, this article will help you gain insight into the design mode used in the JSF framework and gain an in-depth understanding of how it works.

This article describes the design modes used in the JSF framework. The design modes used for parameter discussion include Singleton, Model-View-controller, factory method, state, composite, decorator, strategy, template method, and observer mode.

Design Mode and JavaServer faces (JSF) Technology

First, explain the mode and the JSF framework in a necessary way.

  • Mode.The design pattern is a commonly used method that abstracts the problem and solution. Because the mode is publicly recognized by all developers and structural organizations, the mode can be time and resource sources. In layman's terms, a model is a solution to the issue that a person knows. The mode can be reused, making the solution more robust.
  • Java Server faces.The JSF architecture is a Web application framework. Java Community process (JCP) is a standard framework for Web application development. At present, there are more than 50 frameworks used to develop Web applications. This indicates that the goal of the JSF framework is to mark the line framework!

Return to the terminal

In-depth analysis of the JSF Mode

Now we will discuss various design modes in the JSF architecture. This article will discuss Singleton, Model-View-controller, factory method, state, composite, decorator, strategy, template method, and observer design modes. I will analyze the usage of each mode and its role in the JSF framework.

Return to the terminal

Singleton Mode

The purpose of the singleton mode is to ensure that only one instance of the certificate type is imported, which provides a global access point. When a web application with JSF support is triggered, the Web Container initializes a facesservlet instance. In this segment, facesservlet provides an actual application and lifecycle for each web application. These examples use the singleton mode defined by Alibaba. Generally, only one example of this type is required.

To use a JSF web application, you only need a real example of the application and lifecycle types. Lifecycle manages the entire life cycle of multiple JSF requests. Because their memory and behavior are shared across all requests, the singleton mode makes sense for these objects. The phaselisteners of lifecycle zookeeper is also in singleton mode. Phaselisteners is shared by all JSF requests. In the JSF framework, the singleton mode can be used to reduce the memory usage and provide global access to objects. Navigationhandler and viewhandler (used to establish the border) are examples of using the singleton mode.

Return to the terminal

Model-View-controller (MVC)

The purpose of the MVC mode is to split the data (model) from the view. If the application has multiple representations, You can reuse the controller and model program for the internal programming interface. In the same way, if you need to change the model, you can not change the region to a large extent. The Controller processing uses the dynamic action, and the dynamic action may cause model changes and border updates. When the user requests a JSF response, the request is sent to the facesservlet. Facesservlet is a front-end controller Servlet used by JSF. Like many other web application frameworks, JSF uses the MVS mode to eliminate coupling between the border and model. For centralized processing, the Controller servlet changes the model and imports the model to the render field.

Facesservlet is a controller element used in the JSF framework to evaluate all the useful parameters. For facesservlet analysis, please refer to and use render manager bean to perform various actions on model samples. Backing or managed bean is an example of this model. The JSF User Interface (UI) component is an example of the border definition. In the MVC mode, tasks are divided into developers with different technologies, so that these tasks can be implemented at the same time, in this way, the GUI designer can use the rich UI component to create the JSF interface, at the same time, end developers can create render manager beans to compile their own business workflow program.

Return to the terminal

Factory method mode

The purpose of the factory method mode is to define an interface that is used to create an object, but to practically push the object to the child type. In the JSF architecture, the factory method mode is used to create objects. Lifecyclefactory is a worker object that establishes and returns the lifecycle instance. The getlifecycle (string lifecycleid) method of lifecyclefactory uses the factory method mode. The root certificate lifecycleid is created (if needed) and the lifecycle instance is returned. Custom JSF can now redefine the getlifecycle abstract method to create a self-defined lifecycle example. The built-in JSF validation line provides the built-in lifecycle example. In addition, for every JSF request, facesservlet obtains facescontext from facescontextfactory. Facescontextfactory is an abstract type. The getfacescontext API is opened, and the JSF response line provides a concrete implementation of facescontextfactory and getfacescontext APIs. This is another example using the factory method mode. The actual facescontextfactory implementation creates a facescontext object.

Return to the terminal

State Mode

The purpose of the state mode is to indicate the allocation between different types of memory allocation and memory allocation. Facesservlet references the execute and render methods for the lifcycle instance. Lifecycle uses different phrase for processing JSF requests. In this example, the JSF example line follows the state mode. If this mode is not used, the lifecycle statement line will be collapsed by a large number of conditions (that is, the "if" sentence. JSF creates a simple class for each batch (or segment) and references step. Phase is an abstract type that provides a public interface for each step. Six phrase (STEP): restoreviewphase, applyrequestvalues, processvalidationsphase, updatemodelvaluesphase, invokeapplicationphase, and renderresponsephase are defined in the JSF framework.

In State mode, lifecycle returns the facescontext object to phase. Each segment or segment is changed to the context information provided to it, and then set the standards in the facescontext itself to indicate the next possible step. The JSF dynamic line changes its line in each step. Each segment can be used as the cause of the next segment. Facescontext has two types of labels: renderresponse and responsecomplete, which can be used to change the sequence of response rows. After each step completes, lifecycle checks whether the previous segment has set these standards. If responsecomplete is set, lifecycle places the requested response line completely. If the renderresponse mark is set after a certain segment, JSF will jump over the remaining segment and directly enter the render response segment. If neither of these two standards is set, the lifecycle will begin the next step in reverse order.

Return to the terminal

Composite Mode

The composite mode allows the customer representative to unify the processing of objects and basic objects. Combine objects is the container of basic objects. Use the jsf ui component to construct the UI view in the first and last sections of the restore view segment. Uicomponentbase is an example of the component abstract type in composite mode. Uiviewroot is of the composite type, and uioutput (for example,) is the operator (or basic type ). The type of uicomponentbase defines the public methods of combining and merging objects, for example, compute, and management functions. The child vertex management function, such as getchildren, returns an empty list for the Child vertex and its Child vertex for the combined vertex.

Return to the terminal

Decorator Mode

The purpose of the decorator mode is not to pass through the behavior of a child-type object. The JSF framework has many development points (built-in ). JSF internal rows can use the decorator mode to create propertyresolver, variableresolver, actionlistener, navigationhandler, viewhandler, or statemanager for internal partitions. Generally, you define the internal creation row to be referenced by the internal creation row that has been passed through the structure function. Define a subset of the internal function to change the internal function, and assign other functions to the internal function. If you want to modify the custom viewhandler and modify the calculatelocale method implemented by viewhandler in the internal statement, you can compile the statement as per 1.CustomViewHandlerType:
List 1. mviewhandler clip



public class CustomViewHandler extends ViewHandler {
public CustomViewHandler(ViewHandler handler) {
super();
oldViewHandler = handler;
}
private ViewHandler oldViewHandler = null;
public void renderView (facesContext context, UIViewRoot view) {
//delegate method to oldViewHandler
oldViewHandler.renderView(context, view);
}
//custom implementation of calculateLocale
public Locale calculateLocale(FacesContext context) {
}
}
Return to the terminal

Strategy Mode

The goal of the Strategy Mode is to block different concepts of strategy. The JSF framework uses the Strategy Mode to present the UI component using the Commission render line model. JSF Technical Support supports two present models. In the direct response row model, the UI component parses the received information, and then displays the information. In the decision making model, the solution and the zookeeper operation Committee have provided and established the render manager for the relevant organizations. The latter model utilizes the strategy design mode, which is more active than directly inserting rows. In the Strategy Mode, different algorithms are encapsulated in a single object, and the algorithm can be modified manually. The JSF compiler line can use the existing renderkit instance to compile another Renderer. When the program is used for animation, the JSF component line gets the configuration items to merge these representations with the UI component.

Return to the terminal

Template Method Mode

The purpose of the template method mode is to push the transformed step into the Child type, and define the fixed algorithm step values in the parent type. The JSF framework demonstrates the functions provided by the template method mode through phraselisteners. Using the template method (or "Hook"), the web Author can provide optional rows for different segments, the main segment is still consistent with the definition of the JSF framework. The JSF framework provides phaselisteners, Which is conceptually similar to the changeable step in the template method mode. The JSF framework has six custom segments. Within each segment, web authors can use phaselisteners to provide hooks similar to template method hooks. In fact, this structure is more extensible than the template method mode. You can provide a hook after each segment through the phaselistener with the specified parameter phraseid any_phrase. If the phaseid is any_phase, The JSF connector will reference the phaselistener before and after each segment. In the JSF framework, it is slightly different because phaselistener is not available at all, but in the template method mode, sub-types are usually redefined to define the abstract changeable step in the parent type.

Return to the terminal

Observer Mode

The purpose of the observer mode is to automatically notify all dependent objects (that is, the Inspector) when the metadata of the object changes ). JSF implements the observer mode in the UI component. JSF has two types of internal events: actionevent and valuechangedevent. Actionevent is used to determine the action of a dynamic interface component (for example, a pay-as-you-go operation. When you use a dedicated listener, one or more dynamic listener programs added to the listener are added to the JSF listener. In this case, the user should be subject to the change, or the change of the operator of the subject should be made. All the listening programs (that is, the monitoring tool) added to the pay-as-you-go instance receive the notification that the main listener has changed. Similarly, when the value in the UI component changes, the JSF Parameter Line notifies valuechangelistener.

Return to the terminal

End

The JSF framework utilizes the Singleton, Model-View-controller, factory method, state, composite, decorator, strategy, template method, and observer design modes. Because its architecture is built on the basis of proven design patterns, this is a robust framework that is well utilized in the JSF framework.

Return to the terminal

Additional information

Student

  • Please refer to the Gang of Four design patterns to learn about these design modes.

  • Please refer to the "Life Cycle of JSF Applications" to further understand the JavaServer faces framework (developerworks, March 2005 ).
  • Please refer to the developerworks Java Community. This article describes the articles and programming processes of various architectures on the web and Java solutions.

Obtain product and technical resources

  • Compile JSF from the sun developer network without authorization.

  • Download the free trial version of IBM Rational Software Architect.

Comment

  • And developerworks blogs and join the developerworks community.

  • Discuss with Java on Sun Developer Network -- assumerver faces technology.

Return to the terminal

About the author

Anand is a sun-certified enterprise architecture that has been researching web technologies for years. He provides a wide range of programming and development capabilities for WebSphere administration and control applications. Anand has worked in ibm usa for a few years and is currently working in IBM India.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.