Use tapestry-prop to improve the running efficiency of Tapestry

Source: Internet
Author: User

Introduction to tapestry-prop
It is an extension package written for Tapestry4.0 and provides a new binding prefix "prop :". This prefix is used to obtain the properties of a page or component.
It seems that it is no different from the built-in "ognl:" prefix of Tapestry, but the method for actually obtaining data at the lower layer is completely different from that of OGNL. It uses bytecode generation to obtain the attributes that can be obtained by name in the user class.
"Prop:" The prefix can only obtain simple attributes or attributes represented by paths (Attribute names separated by periods ). For example, "prop: userName" or "prop: identity. admin ".
If the last attribute is read-only or write-only, an appropriate exception will be thrown when they are updated or read separately.
Tapestry5 uses the more mature "prop:" prefix by default (OGNL will be retained, but this article has not been completed yet ).
Use
All you need to do is place the tapestry-prop package in the class path (typically, under the WAR package's WEB-INF/lib package ). Maven will do everything for you. All you need to do is to use tapestry-prop as a dependency package for a project.
You can use the "prop:" prefix in the HTML template:
<Span distinct cid = "@ Insert" value = "prop: userName"> Joe User </span>
Alternatively, you can use the following in the page or component definition file:
<Component id = "userName" type = "Insert">
<Binding name = "value" value = "prop: userName"/>
</Component>
This package is compiled using JDK1.3 and compatible with it.
Comparison with OGNL
"Prop:" prefix is more efficient than "ognl:", but not as flexible as it is.
The advantage is that using it will greatly improve the performance. There is no reflection overhead, and there is no temporary object creation required for OGNL operations.
The disadvantage is that OGNL always calculates the attribute type correctly. "Prop:" The prefix uses the declarative type, just like the Java code compiled during compilation. If a page property is defined by an interface, you cannot use the implementation of this interface to obtain the property (unless those methods are also defined by the interface ).
OGNL also contains a variety of type conversion systems and richer syntax. It is precisely this simple and efficient OGNL (Note: it does not refer to the running efficiency) that makes it selected by Tapestry and does not rely on the reason for code generation.
In terms of performance, there is a significant improvement:

Shows the number of get operation cycles in simple cases (simple attributes) and complex cases (attribute paths. The higher the number, the better the surface performance (the number of cycles in 2 seconds ).
The efficiency of using pure java code and using "prop:" prefixes is almost the same, and there is a significant gap between ONGL. Even worse, every condition contained in an ONGL expression has a huge impact (on the contrary, in the other two cases, the additional condition has almost no impact ). With these factors in mind, the gap between hundreds of Tapestry pages is very obvious.
By default, "prop:" is used for binding.
Use the Configuration Attribute org. apache. Tapestry. default-binding-prefix of tapestry to enable "prop:" For the default binding rules of pages or components :". For example:
<Page-specification>
<Meta key = "org. apache. tapestry. default-binding-prefix" value = "prop"/>
...
</Page-specification>
If no explicit prefix is used for the value defined on all pages, "prop:" is used by default instead of "ognl :". If you use the <meta> tag together with the application definition file (application specification), all the pages and components of the application will be affected.
Download
Beta packages can now be downloaded to the http://howardlewisship.com/repository/ In the Maven 2 Repository

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.