Next Generation BS Development Framework - Echo Tutorial (2)

zhaozj2021-02-11  163

Next Generation B / S Development Framework - Echo Tutorial (2)

principle

Let's take a look at the effect of Echo:

For example, in Demo of Echo, we click on "Disaplay Help" check box, the prompt information is invisible, but the entire page does not change! Includes the drop-down list you choose and the text in the input box. Keep. This effect is very common in desktop programming, and HTML is stateless. After a submission will refresh the entire frame. The general HTML implementation has two ways:

With hidden frame operation, the control department target domain's disaply property. Usually write a lot of scripts. Submit to the server, rewrite the page according to the click button. Such a JSP / XSLT / servlet on the server is very complicated, need Keep all information submitted by the previous page.

Take a look at the concept of echo:

The page is the embodiment of the server-side control. It is like we see a person, but it is to see the light reflected on it. Each component on the page is an embodiment of the corresponding server-side control. Their status, content and draw come The style is saved in the control. Echo is actually a servlet framework, usually it requires a program to return a class representing the main window, and the window contains other controls to represent the input box, buttons, tables, and more. These controls. The Swing is almost the same. We know that the Swing control will produce your own graph graphics painting on the screen. And the ECHO control is output, they will write their own information with HTML / JS to the output, form the page you see. Where is these types? Session. So even if you turn off the window, you have the opportunity to restore it from the session, and it is exactly the same. So many categories of session will not be silent, drag the server? It is possible, But the opportunity is not big. The ECHO control will indeed take up a lot of memory, but usually we will drop the useless controls () in the program. And the session on the server will expire, naturally throwing the spam.

Let's take a look at the implementation of hidden Help:

When writing the page, we will register the ActionListner of the check box control: After being clicked, reflect the display status of the Help area. User request page, the server-side control outputs HTML according to its own status. Check box control is found when the HTML is output. If you register with the listener, you will automatically output a script to HTML. After clicking on the check box, the JS on the page will be submitted to the server with an implicit frame, which button on which button on the echo is clicked, while also All inputs on the page. The server first finds the corresponding server-side control from that guys, updates its status, then calls the list of the button, reverse the help zone display status. After processing, the server returns to step 2 The client sees the updated page.

The above steps look simple. Don't worry, most of the work is automatically handled by the ECHO framework, and we just construct the page and event programs in the first step. Code examples are as follows:

// Reusable help panel control.

Public Class Helppanel Extends Container IMPLEments ActionListener {

// check box

Private Checkbox VisibilityCheckbox;

Private grid.cell description Cell;

Public Helppanel (String Title, String Description) {

Super ();

Grid grid = new grid ();

Grid.setBorderColor (New Color (0xAfbfef);

...

...

VisibilityCheckbox = New Checkbox ("Display Help", True;

// Register listening event

VisibilityCheckBox.AddActionListener (this);

...

...

}

// Implement event monitoring method

Public Void ActionPerformed (ActionEvent E) {

/ / Take the help information status

Descriptioncell.SetVisible (visibilityCheckbox.isselected ());

}

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

New Post(0)