In JSP, I also believe that I also believe in the rear code (in our implementation should be PageHandler and Subcarcies), there is no big deal. PageHandler is designed to prepare data for custom labels, and the custom label is responsible for displaying these data, which is already enough, and event processing PageHandler has also been launched.
But if we need to decide what text on a button is runtime, even if you need to create a custom label control at runtime, then we have a mechanism can be achieved, but it has to increase the complexity of the application itself. So I decided to continue to discuss the server-side control function in WebForm, which allows developers to access the labels declared in the page in PageHandler and their subclasses, and change these controls by code running. .
The mechanism such as WebMM makes the development of the Web close to the development of desktop applications, making the development easier. And I believe that ASP.NET does not have a loss of loss, we can use the JAVA source files of the JSP file generated by ASP.NET and JSP files generated by JSP containers, not difficult to get this conclusion.
Unfortunately, if we realize our ideas under the constraints of the existing JSP container specification, it is inevitable to lose some properties. As we have implemented the reflex mechanism of Java, we have to implement server-side controls, which will inevitably do additional work.
The Java source file generated by Tomcat with TOMCAT will find that each TAG will be instantiated in the corresponding position in the Java source file based on its position in the JSP file (the source code generated by RESIN is also Tomcat is different, Tomcat will instantiate each appearing label, and RESIN is only instantified once for the TAG of the same type), just as the following format:
ButtonTag _button1 = new ButtonTag (); _button1.setPageContext (pageContext); _button1.setParent (null); _button1.setCaption ( "My Button"); _button1.setId ( "button1"); _button1.setOnclick ( "clickme () "); try {int ret = _button1.doStartTag (); if (ret = Tag.SKIP_BODY) {try {if (ret = Tag.EVAL_BODY_INCLUDE) {out = pageContext.pushBody ();!! _button1.setBodyContent ((BodyContent ); _Button1.doinitbody ();} do {... handle tag's body} while (_Button1.DoAfterBody () == bodytag.eval_body_again} finally {if (RET! = tag.eval_body_include) {OUT = PageContext .popbody ();}}} f (_button1.doendtag () == tag.skip_page) Return;} finally {_button1.release ();} Of course, as tag is BodyTagsupport or tagsupport, the generated code will be somewhat different. Suppose all TAG code on the above call page is called A, then we hope that the final generated code has a similar structure: 1: PageHandler Handler = new mypageHandler (); 2: handler.prepareProcess (PageContext); // Before Initialization Work 3: Handler.oninit (); 4: a; // In a execution process, we hope to add TAG's instance in a collection of PageHandler 5: handler.onload (); / / At this time, all controls have been initialized 6: handler.onevent (); // If there is a requesting event, process 7: handler.render (); // Output HTML code to the page, PageHandler calls each control // Write the HTML method, while destroying each control 8: handler.onload ();
In the above steps, 1, 2, 6, 7 is completed by the PageHandler base class, 6 automatically call the appropriate method of MyPageHandler. 4 Commonly completed by PageHandler and each TAG, mainly adding it to myPageHandler in the order of TAG, even to contact the same name control object with the same name control object declared in MyPageHandler. 3, 6, 8 is responsible for rewriting by MyPageHandler, and MyPageHandler is also responsible for the logic implementation of the event.
Thus, after the fourth step, MYPAGEHANDAL can access the TAG instance in the page, and can control these TAGs in 4, 5 steps. In 7, the TAG will write HTML text to the client according to its own latest state. .
Now, there is a problem that we have plagued us in step 4.
(Continued ...) Related Articles:
Simulation Webform (1) in JSP
Simulation WebForm (2) in JSP
Simulation Webform (3) in JSP
Simulation Webform (5) in JSP