Tapestry entry (translated)

xiaoxiao2021-03-06  53

Introduction to Jakarta

Tapestry

(

TapeStry Getting Started)

By Rob Smith, Senior Software Engineer Object Computing, Inc. (OCI)

ORIGINAL:

http://www.ociweb.com/jnb/jnbmay2004.html

Translation: hery tang (hery1977@hotmail.com)

Introduction

Jakarta

TapeStry is an open source Java web application framework. You may say: "Datong is a small thing." Most

In the case, I agree with your point of view, however, as long as I spend a little time study, you will find

TapeStry is very different from other frames, it is worth serious.

Tapestry is a control-based framework for developing a web application similar to developing traditional GUI applications. You use

Tapestry Develops Web Applications You don't have to pay attention to operation-centric servlet API. Quote

One sentence on the TapeStry website: "

TapeStry reinterprets Web application development with objects, methods, methods, properties.

TapeStry 3.0 is about to be released, it has a lot of improvements and new features.

Tapestry's goal

Simplicity

The Tapestry application is less code compared to traditional servlet applications. Most traditional servlet applications contain the following bored

Duplicate tasks: parse the query parameters, process the HTTPSession object, and build URLs.

TapeStry eliminates many of the non-interest "Connect" code in traditional ServelT applications ("Plumbing" Code) enables developers to concentrate on the application logic.

consistency

Tapestry provides a consistent way for the page of the development web application. This helps to eliminate traditional servlet applications. Due to all

The page in the TapeStry application is used to organize the same accessible control, so how the way works is similar.

effectiveness

The TapeStr application has a height of upgradeability, which utilizes the cache and the object pool minimizes the processing time of each request.

The TapeStry app has properties that are similar to traditional servlet applications.

Error feedback

Anyone developing a servlet / JSP application has no question: I have a similar experience: in order to find any mistakes in the web.xml file, you have to spend a lot of time to view the stack information in your browser.

TapeStry has excellent error reporting methods, which is most worth mentioning that it will point out which file and that line leads to errors.

Compare with Struts

Since Apache Struts may be the most widely used web application framework today, take

TapeStry is the only fair to compare it. Here are some observation comparisons, they come from several simple things developed for this article.

TapeStry app and work experience for several Struts projects.

Struts Advantages

1 A servlet / JSP developer is familiar with Struts without having to take too long. however

Tapestry's learning curve presides a little because it is not too the same as the popular web application framework.

2 Struts is widely accepted and used in the Java community. Find a good Struts developer for your project is not difficult,

Tapestry has recently won some attention in the developer community, but there are still many Java veterans who don't know.

What is TapeStry?

3 Since Struts is used in a wide range of use, there are many Struts resources available for reference. Compared to most open source software,

TapeStry has a very considerable resource and document, but there is still a gap compared with Struts.

Tapestry's Advantage 1 You have developed a

TapeStry App No Twymless Write some typical "Connect" code without your servlet application. Although Struts simplifies work, the servlet API is still you need to face.

2

Tapestry's page template is a standard HTML file in addition to several special attributes and identifies. If you are an HTML design master in the development group, you don't understand Java or JSP, which brings you very convenient.

3

The TapeStry page is a standard HTML, so you can edit and preview this page with HTML. When a page needs to modify its appearance, it is not necessary to notify the server to let it recompile the JSP.

4

TapeStry does not require a sufficient profile of the entire application range.

Each page in TapeStry App is independent, changing a page does not affect the developer developer to develop other pages, because there is no configuration file to browse all pages together.

5

TapeStry has excellent error report. If you make an error in a page template or page specification,

TapeStry will point out the line number that causes the wrong error.

6

TapeStry development is a fun. This way, it seems that it seems to be old, but use

TapeStry develops a web application more natural and interesting compared to other popular frameworks. use

TapeStry development is to apply a control-based architecture that is very similar to developing traditional GUI applications.

TapeStry architecture

The TapeStry framework is an extension of the standard servlet API. It requires J2SDK1.2 or higher J2SDK and a compatible application server / servlet container with servlet API 2.2 (or higher).

One

The TapeStry application consists of many pages with a unique name. A page consists of a template and some of the accessible controls. Templates consist of standard HTML tags and some additional properties and labels, these additional properties and labels are to tell

Tapestry Framework This page of this page is

The TapeStry control is composed.

simple

Tapestry application

Build one for the best description

On all aspects of the Tapestry page, we can take a look at this Pig Latin translator application code. This app has only one page. Enter a text value in this page to translate it into Pig Latin, then display the translated value to the user.

in

Each page in the Tapestry application consists of 3 parts: an HTML template, a page specification file, a Java class.

Here are this page screen graphic: The page template is composed of a standard HTML tag and some additional properties and tags, these additional properties and tags are to tell the Tapestry Framework The page of this page is composed of TapeStry controls. The page template is stored in the root directory of the web application. Typically, TapeStry will find and present a page called "Home" at startup. Although we can change this behavior, it will be simpler in accordance with TapeStry. Home.html Tapestry Pig Latin Translator </ Title> </ head> <body> <h1> Pig Latin Translator </ h1> <form jwcid = "@ form" 1 listener = "OGNL : listeners.Submit "2> <table border =" 1 "> <tr> <td> value to translate: </ td> <TD> <input type =" jwcid = "@ textfield" 3 value = "OGNL : InputValue "/> </ td> <tr> <tr> <td> Pig Latin: </ td> <td> <jwcid =" @ INSERT "4 value =" OGNL: PIGLATINVALUE "/> </ td> </ tr> </ table> <input type = "submit" jwcid = "@ submit" 5 value = "translate" /> </ form> </ body> </ html> page template is ordinary HTML, only a small part of TapeStry unique properties and labels. The advantage of this template mechanism is that the TapeStry page template can create and preview in an editor that is visible. Describe the identity of the TapeStry control section is limited and protruded. The JWCID in the identity is the Java Web Component ID of the TapeStry control applied. In the above code break, we are implicitly used controls. Implicit control refers to the controls used directly in the page template,. JWCID's prefix '@' symbol is to inform TapeStry The statement uses an implicit control. Four controls were used in the top of the Pig Latin Translator page: Form1, TextField 3, INSERT4 and SUBMIT 5. They are just four of the Tapestry framework that contains more than 40 controls. In the following example, we will see how to use explicit controls. Explicit controls refer to controls that are represented after declaring in the page specification file. In the previous HTML template, the parameters are specified for the control while using the control. For example, the control Form1 has a listner 2 parameter It specifies the method name of the page class call when the form is submitted.</p> <p>That OGNL: The prefix uses the HTML template through the page, pointing to Object Graph Navigation Language (OGNL). OGNL is a powerful open source expression language that binds properties of the page within the page to the properties of the page class. Now let's take a look at the page specification file. The page specification file is an extension-name XML file. This file has many duties. The most basic is the Java class corresponding to the specified page in numerous duties. The page specification file is stored in the web_inf directory of WebApp. Home.page <? XML Version = "1.0"?> <! Doctype page-specification public "- // Apache Software Foundation // TapeStry Specification 3.0 //" TapeStry_3_0.dtd "Target = _BLANK> http: // jakarta .apache.org / TapeStry / DTD / TapeStry_3_0.dtd> <Page-Specification Class = "Home"> <property-specification name = "infutvalue" type = "java.lang.string" /> <property-specification name = " PiglatinValue "Type =" java.lang.string "/> </ page-specification> page specification file The root element has a Class's property, which specifies the Java class corresponding to this page. This class must implement the org.apache.tapestry.Ipage interface. The page specification is simultaneously pages to define two properties (Property) elements so that Tapestry creates new properties in the page class. The TapeStry framework provides org.apache.tapestry.html.baSepage Class, which implements an ipage interface. The page class is stored in a web-inf / class directory, and other classes you need to use your web application. Home.java import org.apache.tapestry.html.BasePage; import org.apache.tapestry.IRequestCycle; public abstract class Home extends BasePage {public abstract String getInputValue (); public abstract void setInputValue (String inputValue); public abstract String getPigLatinValue (); public abstract void setPigLatinValue (String pigLatinValue); public void submit (IRequestCycle cycle) {String inputValue = getInputValue (); String pigLatinValue = new PigLatinTranslator () translate (inputValue);. setPigLatinValue (pigLatinValue);}} you remind The first thing may be this class why is an abstract class.</p> <p>It also has several abstraction methods to access the InputValue, the PiglatinValue property. Here, TapeStry uses the function of creating subclasses at runtime, which creates the properties you declared in the page specification and generate the appropriate access method. The Submit method of the page class when the form is submitted. Why is this this? Because we specify the Listener property of the FORM control in the page template as: OGNL: Listener.SUBMIT. This means that a listner called Submit will be accessed by the page class Listener. All page classes and control classes are inherited from org.apache.tapestry.abstractComponent. This class is called a property called Listeners. When the Submit method is complete, the page will display the translated words. Finally, the web.xml this web release description file is released. Tapestry, like many other popular web application frameworks, consisting of a servlet, but also a release description file. That release description file should be stored in the web-inflicity. Web.xml <? XML Version = "1.0"?> <! doctype web-app public "- // sun microsystems, incaps//dtd Web Application 2.3 // en" "http://java.sun.com/ DTD / Web-App_2_3.dtd> <web-app> <display-name> TapeStry Pig Latin Translator </ display-name> <servlet> <servlet-name> TapeStry </ servlet-name> <servlet-class> ORG. Apache.tapestry.ApplicationServlet </ servlet-class> <load-on-startup> 1 </ loading-on-startup> </ servlet> <servlet-maping> <servlet-name> TapeStry </ servlet-name> <url -pattern> / app </ url-pattern> </ servlet-maping> </ web-app> Although Pig Latin translation app is very simple, it will allow you to have three components of a page in Tapestry applications. Basic understanding. It also displays a page that creates a Tapestry application only needs to write how few code. Form Enter the verification TapeStry provides some controls to check the user's input. The calibration subsystem is the core of the ValidField control. In the login application we will use the ValidField control. ThevalidField control is within the form, providing a useful feedback and visual error prompt on the client's check. Area is in TapeStry, is quite simple. Tapestry allows The area of ​​text and graphics. For the contents of the regional page, you can add a Properties file to each of the project, or provide a regional template. Provide a resource file for each page to manage and maintain a huge manner The resource file of the global application range is simple. If the area of ​​the page is not just just text information Regionalization, such as the display of the layout of the page, different or consisting of the control, so that the regionalized page template can be used. We will use the TapeStry area in the following login applications.</p> <p>Creating a control TapeStry is published for more than 40 self-contained controls. If you want to know more about TapeStry's own control, please refer to TapeStry Component Reference. To see the application example of TapeStry to access TapeStry Component Workbench. If you find that you need a Tapestry itself does not provide control, you You can create one yourself. Creating your own TapeStry control is similar to the creation of a page. A typical TapeSTRY control is made by a control specification file (XML document), an HTML control template, a Java class that implements the org.apache.tapestry.icomponent interface. This topic is a bit beyond the scope of this article, but if you are interested in learning how to create your own TapeStry control, you can refer to Tapestry's original man, the author of Tapestry In Action, the DESIGNING Tapestry Mega-Components written by the HOWARD LEWIS Ship. TapeStry Login Applications You have seen some of Tapestry in the Pig Latin translator application. Instead of using a complex application showing all the features of Tapestry, you can't get angry, it is better to make you feel a little about TapeStry through some simple applications. The app shows how TapeStry handles page navigation, regionalization, verification, and other features. Here is a screen graphic of a home page, followed by its page template. Home.html <html> <head> <title> Welcome to the Tapestry Login Application </ title> </ head> <body> <h1> Welcome to the Tapestry Login Application </ h1> <span jwcid = "@ PageLink" 1 Page = "Login"> Login </ span> </ body> </ html> This home page page template is a standard HTML other than a Tapestry PageLink1 control in addition to a JWCID property. The PageLink control generates a hyperlink pointing to the Login page. Since the home page does not have any dynamic behavior, it does not require the page specification and the Java class corresponding to the page. Here is the screen graphic of the Login page, followed by its page template.</p> <p>Login.html <html> <head> <title> <span key = "title"> 1Login </ span> </ title> </ head> <body jwcid = "@ body"> 2 <span jwcid = @ conditional "Condition =" OGNL: Beans.delegate.haserrors "> 3 <div style =" color: red "> <span jwcid =" @ delegator "delegate =" OGNL: beans.delegate.firsterror "> 4 Error Message </ span > </ Div> </ span> <p style = "font-weight: bold"> <span key = "hint"> hint: your password is your username spelled backwards. </ Span> </ p> <form jwcid = "@ Form" listener = "OGNL: Listener.login" delegate = "OGNL: Beans.delegate"> 5 <Table> <TR> <TD align = "Right"> <span jwcid = @ FieldLabel "Field =" Ognl: components.inputusername "6> username: </ span> </ td> <td> <input type =" text "jwcid = "InputuserName" 7 value = "simpson_h" size = "30" /> <td> </ tr> <tr> <td align = "right"> <span jwcid = "@ FieldLabel" Field = "OGNL: Components .inputpassword "></p> <p>Password: </ span> </ td> <td> <input type = "text" jwcid = "inputPassword" hidden = "value =" "size =" 30 "/> </ td> </ tr> < Tr> <td colspan = "2" align = "center"> <input type = "submit" jwcid = "@ submit" value = "message: login" /> </ td> </ tr> </ table> < / form> </ body> </ html> Most of this page template is usually HTML. We can see the regionalization characteristics of Tapestry from the page template: it uses a span element, this span element comes with a property called Key, the value of Key maps to a property in the login.properties file. A Body control is declared because it is required for the client's JavaScript verification. Set the Delegate property to Form Component to activate the form input verification. The delegate property is the implementation class of Org.Apache.tapestry.valid.ivalidationDelegate, declared in the page specification. If the verification error occurs, we use the Conditional Component 3 control to determine if Delegate has any errors. If you have the first error 4 to the user. If the OGNL expression OGNL: beans.delegate.haserrors is true, the Conditional control will display its content entity. All page classes and control classes are inherited from AbstractComponent to a property called Beans. This beans attribute is an instance of org.apache.tapestry.ibeanProvider, which uses it to obtain Beans.FieldLabel6 defined in the page specification file by name, which is used to display labels for the InputUserName Validfield control. This FieldLabel control is also used with a form. The verification agent collaboration indicates the input field containing the error. The InputUserName7 control is an example of a display control. Explicit controls refer to controls declared on page specification files. InputUserName and InputPassword controls are explicit, they are combined with FieldLabel to display their DisplayName properties. The following is the resource file of the login page. Login.Properties is equipped with page specification and stored in a web-inflicity.</p> <p>Login.properties title = Login to the Application hint = Hint: Your password is your username spelled backwards login = Login username = Username:. Password = Password: invalidpassword = Invalid Password Here is the page specification for the Login page Login.page <. XML Version = "1.0"?> <! doctype page-specification public "- // Apache Software Foundation // TapeStry Specification 3.0 // en" "TapeStry_3_0.dtd" target = _blank> http://jakarta.apache.org / TapeStry/dtd/tapestry_3_0.dtd> <page-specification class = "com.ociweb.tapestry.login> <bean name =" delegate "class =" org.apache.tapestry.valid.validationdeLegate "/> 1 <bean name = "requiredValidator" ② class = "org.apache.tapestry.valid.StringValidator"> <set-property name = "required" expression = "true" /> <set-property name = "clientScriptingEnabled" expression = "true" /> </ Bean> <property-specification name = "username" type = "java.lang.string" /> <pro Perty-specification name = "password" type = "java.lang.string" /> <component id = "infutusername" type = "validfield"> 3 <message-binding name = "displayName" key = "username" /> 4 <binding name = "validator" expression = "beans.requiredvalidator" /> 5 <binding name = "value" expression = "username" /> 6 </ component></p> <p><Component id = "inputPassword" type = "ValidField"> ⑦ <message-binding name = "displayName" key = "password" /> <binding name = "validator" expression = "beans.requiredValidator" /> <binding name = "value" expression = "password" /> </ component> </ page-specification> The class attribute of the element element and the two Property-Specification elements are similar to the Pig Latin translator. You will find the first new thing -bean element 1, the bean element specifies the instance of an org.apache.tapestry.valid.validationDelegate name "Delegate". The FORM control in the page HTML template sets its parameters delegate to OGNL: beans.delegate, pointing to this org.Apache.tapestry.valid.validationDelegate instance. The bean element 2 specifies the instance of an org.apache.tapestry.valid.StringValidator to verify it for verification. This bean's Required property is set to TRUE indicates that the domain of this bean must be verified. This bean's ClientScriptingNableEnableD property is set to TURE, indicating that the JavaScript verification function of the domain client using this bean is activated. The RequiredValidator bean is used to verify the contents of InputUserName and InputPassword. Control INPUTUSERNAME 3 is specified as ValidField, ValidField is a special version of the Tapestry Verify subsystem. TEXTFIELD control. The message-binding element is used to specify the value of the DisplayName parameter of the InputUserName control, which is obtained from the login.properties file with "username" for the keyword. The Validator parameter for the InputUserName control is set to RequiredValidator Bean, which is the 5 in the page specification. The value of the control value is bound to the UserName property of the page Java class. Control INPUTPASSWORD control specification with control INPUTUSERNAME is almost similar, in addition to the properties of the keywords for acquiring DisplayName and binding page Java classes. Using the ValidField control and providing a validationDelegate for the form (Form), we activate the verification function of the Login form. In addition to the server-side verification, TapeStry also provides client authentication (using JavaScript). Below is the screen capture of a JavaScript error dialog box popping up when the user submits a form without providing a value for the UserName domain. Below is the screen capture of a JavaScript error dialog box when the user is submitted to a form without providing a value for the Password domain. Below is the Java class corresponding to the Login page.</p> <p>Login.java package com.ociweb.tapestry; import org.apache.tapestry.html.BasePage; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid. IValidationDelegate; public abstract class Login extends BasePage {public abstract String getUsername (); public abstract void setUsername (String username); public abstract String getPassword (); public abstract void setPassword (String password); public void login (IRequestCycle cycle) {String username = getUsername (); String password = getPassword (); StringBuffer sb = new StringBuffer (username); String validPassword = sb.reverse () toString ();. if (password.equals (validPassword)) {cycle.activate ( " "); 1} else {string errorMessage = getMessage (" invalidpassword "); 2 ivalidationdeLegate validationDelegate = (Ivalidationdeegate) getBeans (). GetBean ("delegate"); 3 validationDelegate.record (ErrorMessage, ValidationConstraint.cons "); 4}}} It is also abstract, which is also abstract, and it has an abstract method with the Pig Latin translation. Access the properties defined in the page specification (Properties). TapeStry creates username and password properties at runtime. The Login method is just a simple verification whether the user-entered password value is just the reverse of the username. If the password is verified, the user will be led by the Success Page1. If the password is incorrect, we use the keyword "invalidpassword" through the GetMessage () method inherited from org.apache.tapestry.abstractComponent, search the corresponding resource from login.properties 2. We need to record the password error message to the page of the page defined in the page specification. Validation delegate. We can use our name to be specified in the page specification, from the page Beans property 3 in the page Beans attribute.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-115011.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="115011" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.043</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'SlosOHTsi6Oyr7uqdUP8abanr5gdq_2F4irYDQSBa_2B2L9nvQy_2BPZ1a_2FuCG7cVUd6ho8NrFPBEO5c1ju44dFjULJg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>