In JSP to simulate WebForm (3) to this, we also face another problem: implement server-side controls, automatic status, data binding functions in WebForm, and features similar to ViewState can also be implemented in JSP. Although the previously proposed page controller greatly improves the organizational mode of traditional JSP pages, there is a clear life cycle function, but if there is no server-side control, automatic status keep, and data binding, we must also need in actual project development. Make a large amount of heavy, repetitive work to achieve a similar function.
To be able to automatically keep the state, data binding, the premise is to implement server-side control functions. We will first think of custom tags in JSP, actually only custom tags can implement similar server-side controls. Let's talk about the state. For example, the TEXT control in the Form changes its value value. Value will be delivered to the server after the Form is being submitted, but if the server re-sends this page back to the client, do not put this value value in the HTTP text stream. The appropriate location, then, when the client sees this page again, it will not see the value he entered before. That is, the state is lost. And the application is an application, it is necessary to maintain the status of the application, the web application is no exception.
We can customize labels to manage their own status. When the label is executing its DostartTag or DoreTAG, it should be obtained by the Request object, and the value is written back to the client. Then this tag is a label that can be automatically kept.
The status of WebForm remains further. As the DataGrid control in WebForm, when you load the page, we read the data from the database and bind to the DataGrid, then the page is transferred to the client, and the user has repeatedly re-requested the server (request this page again, Continuous data in DataGrid will also transfer back to the server). After the server is processed, you need to transfer the page back to the client again, but this time we don't need to request the database again, DataGrid automatically keeps the status, because it can get from the client Back of its own data. However, the Request object can only get the value of certain attributes of the FORM control, and it is a simple type of value. How do DataGrid gets its own value from the client from the client? !
The answer is to use hidden fields, binding to the complex data on the DataGrid (usually a two-dimensional table) will be processed by WebForm to assign a hidden field, and the value of the hidden field will be obtained by the request, so that DataGrid will be The data obtained by the hidden field is reduced to the data that is also acceptable to DataGrid as the reverse process just contrary. WebForm's ViewState feature is also achieved.
So we said that server-end events in WebForm trigger as callbacks, or returns, partly because the client request is the same page, part of the reason is that the value of the automatic keeping state is also reaches the server again with the client. .
It can be seen that automatic state keep and viewState sacrificed network traffic. Some of the programmers will be dissatisfied, how do you send me a lot of things in DataGrid and give me a return! I will request another database once again? The solution is to set the DataGrid's EnableViewState property to false so that WebForm will not sneak a large pile of DataGrid in Hidden. Abuse automatic status keeps performance decline, you only need to view the source code for the ASP.NET page, where there is a hidden field of _ViewState, if it is a long longer, then you should consider the control of certain controls EnableViewState property is set to false. In JSP, we want to achieve automatic status and viewstate, of course, this method is also used. These work is processed in the PageHandle base class and custom labels. We will worry about us when we use.
There is also data binding. Realizing this should not be difficult, there should be a corresponding custom label to handle this thing, not much here.
However, the server-side controls have those features that do not have custom tags? The most important thing is: The server-side control can be accessed in the rear code and can pass the attributes of the code operating control.
Is this really important? I believe everyone has a view. But this does not affect the automatic retention state and data binding. (Continued ...) Related Articles:
Simulation Webform (1) in JSP
Simulation WebForm (2) in JSP
Simulation Webform (4) in JSP
Simulation Webform (5) in JSP