Next generation B / S Development Framework - Echo Tutorial (8)
Data binding
People who like lazy people like data binding.
Many desktop development tools provide control data binding functions. Unfortunately, Echo has not yet. In my hand project, a table has hundreds of fields, you have to edit from Form, a page is not enough, Several pages come to segmentation. Even if Echo saves a lot of trouble, you still have to read data from each TextField, and then put it in Model. So I wrote a small binding tool, so using echo, A person can deal with this dinosaur-level page. Let's take a look at how to use:
User User = new user (); // Data DataBINR Binder = New Database; // Binding Controller Binder.bind ("Name", CMBName); // Bind to drop-down list Binder.bind ("Tel ", txttel); // Bind to the input box
If you change the properties of the user in the program, you can call Binder.Rebind () update. The user is entered, and the input Binder.Update () can update the input to the user. Binder Some small features:
The REFLECTION will take the get / set method when binding, then find the visible member variable. Automatically try to convert, such as values, date. Some special controls may not be able to get its properties directly, such as ButtonGroup can only return Which button is selected. Therefore, specific controls need to write plugins to provide virtual property. If you need to bind to the variable name instead of specific objects, you should bind the USER drop array or list. In fact I defined. Several data sources, if you want, you can write the data source of ResultSet / XML XPath. The data source provides data navigation function. Allow browsing in the data, as long as the simple rebind can be updated, the page is default the TEXT attribute for the control Operation, but you can specify a binding to other properties, such as Visible. Support for one-way binding: read-only / only update. A binder corresponds to a data source, Bindgroup is unified to a group of binders.
Table also has a binding: Tablebind. Its constructor is:
Tablebind (Bindsource BS, Table Table, String] Fields)
The Table and Grid in the Echo are very different. Grid is a container that is similar to layout. It needs to be added to Component in the inside. And Table is only accommodating various data, and the specific performance needs to be used to use CellRender. Can be made or Turn data into a button. With the data binding of the table. You can focus on the beautiful Cellrender.
In many applications, there is often a changed primary data. They are often reflected in the drop-down list or a set of radio / multi-selection buttons. When users are used to, when entering the data, it often encounters which master data does not go to open a window maintenance, then The new data is reacted on the page just entered. So I made a SelectManager, which used the cached master data, and updated all users' pages, not just the current user.
Say more sentences:
Data binding is just a lazy first step, code generation is the second step. We will use some tools to generate a complete set of HTML / JS, XML / XSL ... These generated for B / S architecture. Things tend to be modified, then modify it again ... Echo's HTML is dynamically generated, also gives me a higher level code generation: Java's class file, use OO method to reuse or adjust it.
Thinking about it: Why do not use the data source of generating code to generate a web page? For example, the table's field / primary key / description information is obtained according to the JDBC Metadata. Then automatically construct a table's entry and browse interface. Even according to foreign key information Constructing the association entry. Such a page is almost maintained, and the modification of the over structure will be reflected right away.
Another very interesting idea is to construct a page according to data. In Notes and SAP development, developers will generate a very good interface as long as they tell the page to read which variables are generated, including drop-down list and data verification. These variables already contain Rich format information and even prompt information. Java can also do it, but have not seen it. It can borrow Schema, which is very comprehensive, and can be flexible. Schema can not only define information of single data, but also define Structural information. That is to say, SCHEMA can describe a screen requirement, which can be used as a standard for automatically generating interfaces, allowing the program to construct the corresponding ECHO interface while reading SCHEMA, and then directly enters XML compliant with SCHEMA. Such functions Let us make more convenient to use WebService because the data description of WS is Schama. These are unripe ideas, welcome to discuss. In addition, I will put in one example, provide download in the later tutorial, For reference only, welcome feedback.