On the elegant design and example of view layer in MVC framework
Source: Internet
Author: User
Design 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.
A more friendly framework for MVC, in the simplification of server application development, but also need to design in view this layer does not affect the work of the interface, the most basic requirement is not too much to add some design software unsupported tags and other elements ( Many of the tags in Struts are not supported in Dreamweaver. Here we take easyjweb as an example to explore how to achieve a more reasonable design in the view layer.
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.
Of course, to make the interface can be combined with the background program logic, the display interface and program logic need a certain dialogue protocol. Easyjweb as an MVC framework, there is also such a dialogue protocol, which is the interface template identification language in Easyjweb.
In the current release, the Easyjweb interface template Identification language uses the Apache open source Velocity template engine (template engine), which will, of course, add more template engines to the framework users to select from time to time.
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 four simple template script statements to achieve:
1, $!obj directly returns the object result.
For example, displays the value of MSG for Java objects in HTML tags.
$!msg
Displays the value of the MSG object processed by the Htmlutil object in the HTML tab.
$! Htmlutil.dosomething ($!MSG)
2, #if ($!obj) #else #end Judgment statement
For example, in easyjweb various open source applications, we often see examples of MSG for pop-up prompts.
<font color= "#FFFFFF" > title #orderpic ("title") </font>
Summarize:
Of course, in the actual application projects, in order to achieve a more user-friendly interface, human, there will be a lot of complex, variable demand. such as according to the different state of the object, display different hint color, prompt voice and so on function. At such times, you still have to use too many template scripting features, most of the requirements can be resolved in a flexible manner, some information can be directly in the object to increase the logic of conversion information, some interface requirements can be used in the interface with a specific interface of the expression of the way to achieve, such as using JavaScript in HTML pages, using WMLScript in Css,wap pages, and so on. Only, in order to ensure that your system core is not affected by the interface and control, in order to better expand and maintain.
We want you to be a real program whiz, not just a proficient scripting language on the surface, so you don't want the vast majority of Java developers to spend too much time on the view layer.
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