Alternative method of web MVC (reproduced)

xiaoxiao2021-03-06  67

Although current popular is based on request-driven Web MVC frameworks, there are two important alternative development methods in J2EE: portlets and event-driven Web MVC frameworks.

1, Portals and Portlets

(1 Overview

l Web Portal implements a single HTML page consisting of multiple completely unrelated parts, each part is implemented by the Controller-View component

l Portal container is controlled by workflow

l Controller-View components called portlets in Portal

l Each portlet is an self-interacting component, not a lower level representative of a workflow control.

l Portlets are like the MVC controller, receive a representation request, check the request parameters, create a data model, and turn to the display view.

(2) JSR168

l JSR168 is a Java's portlet specification that defines APIs and environments similar to servlet: javax.portlet.portlet

L Unlike the servlet, the portlet is not a component responding to the HTTP request processing, but a notification is obtained through the Workflow processor of the Portal container, responding to the callback components of various commands:

Ø DOVIEW (RenderRequest, RenderResponse): Show portlet default view

Ø Doedit (RenderRequest, RenderResponse): Show portlet editing view (if supported)

Ø DOHELP (RenderRequest, RenderResponse): Show portlet help (if supported)

Ø Processction (ActionRequest, ActionResponse): Calls by the container (for any view mode) when the portlet is submitted

l In a typical JSR168 portlet, the DoView acts as a component controller, preparing a data model, possibly accessing the intermediate resource and services, and stepping to JSP as a portlet view

l Self-migration form submission, use standard HTML

tags, use portlets Tag to specify its Action property, portlet container uses the submitted parameters to call ProcessAction, call Doview, doedit by returning view mode Or dohelp

(3) Deploy portlet

l Portlet collection is deployed in a standard WAR file, just the definition of portlets in /Web-inf/portlet.xml, not using web.xml

(4) Sharing

l Portlet specification defines its own MVC mechanism to accommodate the demand for portlets.

l If the portlet container is running in the J2EE server, the portlet can access the resource and services of the intermediate layer through JNDI.

l However, portlets are impossible to share local resources to other components of the web application because they are located in an independent environment.

2, event-driven Web MVC framework

(1 Overview

l Event Drive Framework is to apply desktop UI programming to a web environment

l They do not focus on the form commit to the URL that maps to the controller to perform request processing, but to associate form components to listener l in event calls. They usually do not focus the focus model objects. Embedded view Technology, but put the web page as a hold state and knows any application of different skin,

l In the framework of Echo and Wings, provide a programming model close to Swing, generating the actual HTML code by the UI component class, which makes the web designer not easy to customize, limit the flexible integration of the custom HTML and JavaScript, and generate A large number of unwanted session status

l Other frameworks like TypeStry and JSF (JSR127) combine template methods and event processing mechanisms: HTML layout defines in templates such as JSP and Velocity, actual workflow and view present the frame controller of format events in the processing page. management

l The next template-based approach is somewhat by Microsoft's ASP.NET, like JSF in many aspects like ASP.NET in the Java world.

(2) TypeStry

l TypeStry focuses focus on a fully separated Java code and HTML template, dividing each page into 3 parts:

Ø HTML Template: Pure HTML tag, contains dynamic parts marked by JWCID attribute

Ø Page specification: Define the page implementation class and components used in the page

Ø page class: Define models and page listeners

l Each page consists of any quantity and nested components, each component is also divided into three parts:

Ø HTML Template: For the pure HTML tag of the component, contains the dynamic part of the JWCID attribute tag

Ø Page specification: Define components to implement classes and nested components used

Ø page class: Define the listener of the model and components

l TypeStry's HTML template does not contain scripts and custom tags, but a specific tag identified by JWCID (Java Web Component ID) attribute, typical tags are , at runtime, these tags will be The HTML code generated by the TypeSTRY component is replaced

l TypeStry's HTML template can be displayed in a browser and an HTML editor, and non-standard JWCID property tags will be ignored.

l TypeStry's HTML template and JSP or Velocity use the dynamic view of the mark code, dynamic expressions, and control flow logic. It is a static template that requires page specification synthesis to generate actual dynamic views.

l TypeStry handles the workflow management without having to contact HTTPSERVLETREQUEST or HTTPSERVLETRESPONSE

l The data submitted by the form is bound to the attribute (model) of the page or component instance, the control logic is implemented by the listener of the page or component class, performs actions or go to different pages (Controller)

l TypeStry's page instance is the Pooled; page properties If you need to keep the same user between different pages, you can mark as lasting, TypeStry saves page properties to httpsession

l TypeStry applications require an application specification to define a valid page, which also determines the engine class used.

l The engine class is the status manager of the server side, which is usually saved in the HTTPSession to maintain two types of application-specific objects: Ø Visit object: Contains all status of the current access user, corresponding to HttpSession properties

Ø Global object: Share for all engine instances of the application, corresponding to servletContext properties

L and page, the engine example is Pooled

(3) JSF

l JSF focuses focus on creating a form using the JSP tag library, embedding the verifier and navigation rules in the JSP code.

l Depesers, navigation rules, and managed beans (such as form objects) define in Faces-Config.xml

l JSF view is called via FacesServlet (View)

l action is implemented by the command-style event listener. After the call is called, the result is usually the navigation rule reference for the steering view, and the object in their environment can be accessed through FaceSContext (Controller)

l Form object is simple JavaBean (Model)

l Components are implemented by custom tags, which can change the skin through different plug-in renders, which allows reuse of the same JSF view to different target formats, such as HTML and WML (view independent model)

3, selection of various Java / J2EE schemes

l ASP style script programming: pure JSP

l CGI style request processing: servlet, mainly binary content

l - based custom MVC solution based on servlet / JSP: simple workflow

l Use JSP request to drive the web mvc framework: struts, webwork, etc. (Many options)

l Using Velocity, FreeMarker, etc., the request to drive the web mvc framework

l Using XSLT, XMLC, etc., XML technology, etc., to drive web MVC framework

l Swing style presenting GUI components: Echo, Wings

l Create: TypeStry based on page specification

l ASP.NET style GUI creation: JSF

转载请注明原文地址:https://www.9cbs.com/read-89327.html

New Post(0)