Unmi's Struts2 Learning notes (11)

Source: Internet
Author: User
Tags constant

You can be a good citizen, for the group efficiency and the following personal order, however, not only can not improve the efficiency of the group, and you are bound to lose a lot of opportunities, no one praise you, even less sympathy, had to consciously naïve.

1. Template Directory-> Topic directory-> Theme (template file) This is the template/topic directory organization. Take the actual example, open Struts2-core-2.x.x.jar to see a template inside, under template there are 5 directories Ajax, css_xhtml, Simple, XHTML, and archive, the first four of which are AJA X, css_xhtml, simple, XHTML topic directory, each topic directory has its own template files, mainly FTL files, as well as CSS and JS files. The last archive is the archived theme directory, with Ajax, Simple, XHTML, and template files as. vm files. So the template language that Struts2 strongly recommends is freemarker, not Velocity, to take a good look at freemarker later, only know Freemarkder more XML.

2. Above see template directory name is template, is Struts2-core-2.x.x.jar, in fact directory name is specified by Struts.ui.templateDir constant, only the default value is template. This means that Struts 2 loads specific template files sequentially from the template directory of the Web application or from the Classpath template directory (package).

3. For example, if we use a SELECT tag and specify that the subject is XHTML, the order in which the template files are loaded is (1) WEB application/template/xhmlt/select.flt (2) Classpath/template/xhtml/select . FTL. Struts2 default is the use of Freemarkder template technology, you can set the constant Struts.ui.templateSuffix to change the default template technology, optional values are FTL, VM, JSP. But for VM and JSP to provide a complete implementation of their own, Struts2 did not help you do this.

4. Sometimes we want to customize the theme, such as you want to enter the box before the label to display the red color, you do not want to verify the error tip in the input box just above the right. Of course, you can modify the Struts2-core-2.x.x.jar in the template under a topic template file, or a copy of the WEB application directory to the template directory to modify the template to customize, this is always a bit uncomfortable. STRUTS2 also supports two more flexible ways of customizing themes. Wrapping and inheriting existing topics can be used at the same time.

The simplest way to customize a theme is to use the load priority of a theme template to place a custom template file in a higher priority directory, such as putting a TEXT.FTL in the web-inf/classes/template/xhtml/directory, which will overwrite The definition of the TEMPLATE/XHTML/TEXT.FTL in the Struts2-core-2.x.x.jar.

5. First look at a packaging example, the content of the COMBOBOX.FTL in XHTML is as follows:

< #include "/${parameters.templatedir}/

${parameters.theme}/controlheader.ftl"/>
< #include "/ ${parameters.templatedir}/simple/combobox.ftl"/>
< #include "/${PARAMETERS.TEMPLATEDIR}/XHTML/CONTROLFOOTER.FTL"/>< #nt/>

It is on the basis of SIMPLE/COMBOBOX.FTL packaging on a CONTROLHEADER.FTL and a CONTROLFOOTER.FTL, the limitations of the packaging is that you are still going to provide a separate template file for each UI component, that is, the full set.

and design patterns in the packaging (decoration) pattern is the same, such as Bufferedinputstream packaging InputStream, but in Bufferedinputstream provides a full set of the same as the InputStream operation method.

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.