Separation techniques of code and view templates in B/s application development

Source: Internet
Author: User

What kind of MVC is needed

In the application development based on B/s, from the basic technical Division of labor is two large, one is the software display interface, the other is the program logic. In the time of the scripting language of n years ago, whether ASP, PHP or JSP, we basically are the two soft together. Although we are trying to do a lot of functions or include files to try to achieve software reuse, we still can't meet the changing needs of our users, mainly because the previous pure script encoding is not very good to support and apply the power of object-oriented (oo) domain.

In the common B/S software project, the interface design includes the HTML interface, the WAP interface and other interfaces which are represented by the text character protocol. In our contact with the most HTML page as an example, when doing these interfaces often need to use Photoshop or fireworks and other graphical interface design tools for global design, and then use the Dreamweaver and other HTML page production tools for processing. and powerful program logic and background processing are completed by the server-side programs, these programs have a high degree of stability, its development tools such as JBuilder, Eclipse and so on the view layer interface is not very good support (of course, those with Notepad to write the interface of the application except), This makes the design of many MVC frameworks impossible to align.

With the advent and application of the MVC framework such as struts, our view layer becomes simpler and easier. However, there are still times when you need to insert Java code into a page, such as a nasty @< import>. Most of these MVC frameworks provide a range of custom tags, and when custom tags become more complex, it's simple for programmers to scare our artists and page makers.

How pages and programs are separated

Easyjweb as a fast Java WEB MVC Framework, its design goal is not only to simplify the code writing work of software developers, but also to facilitate the work of interface designers. Easyjweb is based on a template, built on a powerful and simple template engine velocity, and a certain expansion of velocity.

Velocity is a java-based template engine (template engine) that allows anyone to simply use the template language (template language) to refer to objects defined by Java code. As a relatively perfect template engine, velocity is powerful, but it also increases the complexity of the application.

Theoretically you can use all velocity scripts and functions in the Easyjweb template, but we do not recommend that you use too many complex script expressions in the interface template, and in the last resort, do not add any complex logic to the interface template, let alone the variable declaration in the interface template. logical operators, and so on.

In Easyjweb, we provide four basic template scripting statements that basically meet the requirements of all application templates. These four template statements are simple and can be added directly by the interface designer. In the current practice of many easyjweb, we see that all interface templates can be summed up in only the following five simple template script statements to achieve:

1, $!obj directly returns the object result.

2, #if ($!obj) #else #end Judgment statement

3, #foreach ($info in $list) $info. Somelist #end Loops through the objects in the collection list and handles them accordingly.

4, #macro (macroname) #end script function (macro) calls, is not recommended in the interface template for a large number of use.

5. Include file #include ("template file name") or #parse ("template filename")

Easyjweb also provides a number of tool classes that can greatly simplify the writing of templates. such as Commutil in the Torowchildlist,tagutil in the options.

By using the Velocity template script, you can make the view no longer have any markup or symbols related to a particular language other than what is relevant to the data display. Since the velocity template is not disruptive to the interface, even if a series of template tags are added, the artist and the page maker can see the pure natural interface view without any extra special processing. In addition, you can learn how to use velocity scripts in half an hour, and change the system interface according to the customer's aesthetic, custom and even mood.

Convenient for others is convenient for themselves

One important reason why Easyjweb Advocates page templates and program separation is to liberate programmers. To give others convenience is equal to their convenience, Easyjweb contains such a philosophy of life. Therefore, as a programmer, after a period of contact with Easyjweb, you will find that in addition to make the view interface of the staff convenience, easyjweb the main concern is that we are often criticized the aesthetic, the most annoying to the messy HTML code, CSS style and the image of the fear of the programmer. Therefore, Easyjweb makes it very easy for programmers to deal with the content of the view layer. For example, to send an object to the view layer, simply use Form.addresult ("name", obj) in the action, and send an object to the view layer by dividing it into attributes, and you can use the Form.addpo (obj) method directly ; To read data from a view-level form to an object, only Form.topo (obj) is required; Easyjweb to deal with data conversion, validation, data protection and many other details.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.