In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to configure the page of Tapestry". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to configure the Tapestry page.
1. Start.tml and Start.java of Tapestry 5.1,
Tapestry does not need to configure the welcome page in Web.xml, but also uses a way that the convention is greater than the configuration. The default starting page is Start in the pages directory. The page in Tapestry consists of two parts: a Java class and a template file with the same name (similar to the suffix: tml in jsp,Tapestry). The Java class is required, and an empty class must be generated even if there is no code. The tml template is also required in most cases, but in a few cases, such as returning a binary stream, it may not be needed.
The tml template file can be placed in the webroot directory or along with the Java class in the src directory all the time.
2. The jump of the page in Tapestry 5.1.What can be used to specify the jump page:) @ InjectPage
In Tapestry, the jump of a page is different from a framework such as Struts. What Struts does is that Action returns a string, and Struts searches for a match in the xml configuration file to determine which page to jump to. Tapestry does not have a similar configuration file, which refers to the jump page in the current page. For example, if you want to jump from Start to Register page, you need to inject Register page into Start. The sample code is as follows:
Class Start {@ InjectPage private Register register; Object onSubmit () {return register;}}
It is worth noting that the modifier for onSubmit is not the usual public, but the default level (or package level), which is recommended by Tapestry. * *, which is lower than public, so that the event handlers of the page class are not exposed, and not everyone else can call them casually. Second, it is higher than the private level, so that if the test needs, you can put the test class in the same package to facilitate the test.
There are six ways to specify the page to be redirected in the Tapestry event handler
A, nothing is returned, that is, the return type is void, so the page does not jump, but just refreshes the current page
B, string. Tapestry looks for the class that corresponds to the string
C, class. Generally speaking, it is a Page class, which is better than returning the class name (string), because in this way, the program will not make an error after the class is renamed.
D, Page instance
E 、 Link
F, Stream (stream), such as returning pdf or Excel files.
3. Expressions in Tapstry 5.1pages
Similar to jsp
< %= 变量名%>In this way, the syntax of Tapestry is ${variable name}, where the variable name needs to have a get method in the corresponding Java class of the page.
4. Other page-related considerations in Tapestry 5.1
◆ in Tapestry, pages are called page templates (Page Template). The page template for Tapestry must be a Well Formed Xml, and you need to introduce the Xml namespace of Tapestry to use the components of Tapestry. Example:
< html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">◆ can use expressions in page templates to get the value of a variable. This expression is called Expansion in Tapestry.
◆ said in the previous article that a page template must have a corresponding Java class. The most basic Expansion in Tapestry is a property of the Java class. For example: ${userName} this is an Expansion that can be used in a page template. In order to display the user name correctly, there must be a corresponding public String getUserName () method in the Java class. Note: it is a getter method, not necessarily public String userName. In fact, if there is no userName attribute, but only the getUserName method, the application will run correctly.
◆ Expansion is case-insensitive, which means that ${userName} and ${UserName} are equivalent.
◆ uses Expansion, and we can display not only the properties of the Java class, but also the properties of that property. For example, the Java class has a date attribute public Date getBirthday (). Then, in the page template, you can use it like this: ${birthday.time}, which is equivalent to calling getBirthday (). GetTime ()
◆ can also call non-getter methods explicitly: for example: ${birthday.hashCode ()}, starting with Tapestry5.1, you can use the property as an argument to the function call.
◆ can use?. To call the method: for example: ${birthday?.time}, so that even if birthday is null, the page will not report an error.
◆ Tapestry's Expansion generates class files at compile time, rather than using reflection to take values at run time. The authors of Tapestry believe that this is one of the possible reasons why Tapestry outperforms Struts2 (note: Howard Lewis Ship is also just a guess).
Several instructions for the use of Expansion for ◆ Tapestry:
A, the white space next to Expansion will be ignored.
B, integers and decimals can be preceded by a negative sign
C, constants are all decimal.
D, string needs to be in single quotation marks
E, you can use.. To represent a range, for example: 1. 5, 1 to 5
At this point, I believe you have a deeper understanding of "how to configure the page of Tapestry". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.