Tapestry entry (translated)

zhaozj2021-02-17  50

Introduction to Jakarta Tapestry (Tapestry entry) by Rob Smith, Senior Software Engineer Object Computing, Inc. (OCI) original (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 small things are." In most cases, I agree with you, however, as long as speaking a little time study, you will find that Tapestry is very different from other frames, it is dedicated to treat . Tapestry is a control-based framework for developing a web application similar to developing traditional GUI applications. You don't have to focus on the operation-centric servlet api with Tapestry (Operation-Centric) Servlet API. Quote a sentence on the TapeStry website: "TapeStry uses objects (Objects), method (Properties) replaces past URLS and query parameters, reinterpretation of web application development. Tapestry 3.0 is about to be released, it has a lot of improvements and new features. Tabestry's target Simplified Tapestry application is less compared to traditional servlet applications. Most traditions The servlet application contains the following tired and repeated tasks: parsing the query parameters, handles httpsession objects, and builds urls.tapestry eliminates many of the "Plumbing" Code "in traditional ServelT applications (" Plumbing "Code) enables developers to concentrate on application logic Come up. Conformance Tapestry provides a consistent way for the development of web applications. This helps to eliminate traditional servlet application development. Since all TapeStry applications are organized with the same accessible controls, So the working method is similar. Efficiency TapeSTR Application has a high degree of upgradeability, which utilizes the cache and object pool minimizes each request. The Tapestry application has the performance that is similar to the traditional servlet application. Error feedback any development servlet / JSP application has no question: In order to find out what is wrong with 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 mode, the most worth mentioning is It will point out which file and that line leads to errors. Since Apache Struts may be the broadest web application framework for today's application, TapeStry is the only fair. Here are some observations, they come from this Several simple TapeStry applications developed and work experience for several Struts projects. Struts Advantage 1 A servlet / JSP developer is familiar with Struts No need to take too long. However, TapeStry's learning curve presides, because it is popular The web application framework is not too different. 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 old hands. I don't know what TapeStry is. 3 Since Struts is used in so widely, there are many Struts resources available. Compared to Most open source software, TapeStry has very considerable resources and documents, but there is still a gap compared to Struts.

Tapestry Advantage 1 You have developed a TapeStry application without paying attention to the Servlet API, you don't have to write some typical "Connect" code for your servlet. Although Struts simplifies work, the servlet API is still you need to face. 2 Tapestry Page Template In addition to several special attributes and identifies are a standard HTML file. If you are an HTML design master in the development group, you don't understand Java or JSP, which brings you very convenient. 3 Because the TapeStry page is a standard HTML, you can edit and preview this page with the HTML you have obtained (Wysiwyg) editor. When a page needs to modify its appearance and do not need to notify the server to restore the JSP. 4 TapeStry does not require a sufficient, the entire application scope profile. 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 an excellent error report. If you make a mistake in a page of the template or page specification, TapeStry will indicate the line number that causes the error. 6 Developed with TapeStry is a fun. This way, it seems that it seems to be old, but use Tapestry to develop a web application more natural and interesting than other popular frameworks. Developing TapeStry is to apply a control-based architecture that is very similar to developing traditional GUI applications. The TapeStry Architecture Tapestry Frame 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). A TapeStry application consists of many pages with unique names. A page consists of a template and some of the accessible controls. Templates consist of standard HTML tags and some additional properties and tags, these additional properties and tags are to tell the Tapestry Framework These pages are composed of TapeSTRY controls. Simple TapeStry App For the best description, we can take a look at the code of this Pig Latin translator application. 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. Each page consists of 3 parts in the TapeStry application: 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 // en" "http://jakarta.apache.org/tapestry/dtd /Tapestry_3_0.dtd> <page-specification class = "Home"> <property-specification name = "inputValue" type = "java.lang.String" /> <property-specification name = "pigLatinValue" type = "java.lang .String "/> </ page-specification> The root element of the page specification file has a class's property, which specifies the Java class corresponding to this page. This class must implement the org.apache.tapestry.Ipage interface. Page specification The page defines two properties (Property) elements so that Tapestry creates a new property in the page class .tapestry framework provides ORG.APache.tapestry.html.basepage Class, which implements the iPage interface. Page class is stored in Web- Inf / classes directory, other classes required for your web apps together. 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; public abstract string getpigilatinvalue (); public abstract void setPigLatinValue (String pigLatinValue); public void submit (IRequestCycle cycle) {String inputValue = getInputValue ();. String pigLatinValue = new PigLatinTranslator () translate (inputValue); setPigLatinValue (pigLatinValue);}} The first thing you might want to remind This is why this class is an abstract class. It also has several abstraction methods to access the InputValue, the PiglatinValue property.</p> <p>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. Creating a control TapeStry is published for more than 40 self-contained controls.</p> <p>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" "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" 2 Class = "org.apache.tapestry.valid.stringvalidator"> <set-protety name = "required" expression = "true" /> <set-protety name = "clientscriptinagenable" express = "true" /> </ bean> <propertyty @Property -specification name = "username" type = "java.lang.string" /> <property-specification name = "Passwo Rd "type =" java.lang.string "/> <component id =" infutuser "type =" validfield "> 3 <message-binding name =" displayName "key =" username "/> 4 <binding name =" Validator "Expression =" beans.requiredvalidator "/> 5 <binding name =" value "expression =" username "/> 6 </ component> <component id ="</p> <p>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 "Page-Specification" and the two Property-Specification elements are similar to the Pig Latin translator application. You will find the first new thing -bean element 1, bean elements specify a name "delegate". The form of the name "Delegate". The FORM control in the page HTML template sets its parameter delegate to OGNL: beans.delegate, pointing to this org .apache.tapestry.valid.validationDelegate instance. Bean Elements 2 Specify the name "RequiredValidator" for verification. This bean's Required property is set to True indicates that this The bean's domain is to be verified. This bean's clientscriptingNableEnableD property is set to TURE, indicating that the JavaScript authentication feature of the domain client using this bean is activated .RequiredValidator bean is used to verify the content of InputUserName and InputPassword. Control INPUTUSERNAME 3 Control specification declares that ValidField, ValidField is a TEXTFIELD control for TapeStry verification subsystem. The measureage-binding element is used to specify the value of the displayName parameter of the InputUserName control, this value is keyword with "username" Login.Properties 4 files. INPUTU The Validator parameter of the sername control is set to RequiredValidator Bean, which is the 5 in which we declared 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-28583.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="28583" 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.047</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 = '5ChHNO1KJgY6T4xWL7VrPuKCQleAbNC0wVJ5r8chEF2JYwxS9qLIkBLBr2EXsijCegpTCNwF_2BHnU0GMtdSplsA_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>