Tutorials to .com

Tutorials to .com » Jsp » Tapestry-hivemind » 1 Cart tapestry, landing

1 Cart tapestry, landing

Print View , by: iSee ,Total views: 6 ,Word Count: 3107 ,Date: Thu, 16 Apr 2009 Time: 4:46 AM

OK, the book with access to the back Now, we set up the project have been completed, for example Cart, the first page should be a landing page. Landing page should have a form, enter a user name, a password input, but also the need for a user name and password for effectiveness.

Home.java modify the following documents:

   com.tapestry4; package com.tapestry4;    org.apache.tapestry.IRequestCycle; import org.apache.tapestry.IRequestCycle;    org.apache.tapestry.html.BasePage; import org.apache.tapestry.html.BasePage;    class Home extends  BasePage { public abstract class Home extends BasePage (           public abstract String  getUsername(); / / User name public abstract String getUsername ();           public abstract String  getPassword(); / / Password public abstract String getPassword ();           public  void loginSubmit(IRequestCycle cycle) { / / Login form of monitoring methods public void loginSubmit (IRequestCycle cycle) (                   .out.println( this .getUsername()); System. Out.println (this. GetUsername ());                   .out.println( this .getPassword()); System. Out.println (this. GetPassword ());           )   ) 

In Home.page document, we read as follows:

   encoding= "GBK" ?> <? xml version = "1.0" encoding = "GBK"?>   <! DOCTYPE page-specification PUBLIC     "- / / Apache software foundation / / tapestry Specification 4.0 / / EN"   > "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">    <page-specification>       /> <property name= "username" />       /> <property name= "password" />        type= "Form" > <component id= "loginForm" type= "Form">            value= "listener:loginSubmit" /> <binding name= "listener" value= "listener:loginSubmit" />       </ component>        type= "TextField" > <component id= "username" type= "TextField">            value= "username" /> <binding name= "value" value= "username" />       </ component>        type= "TextField" > <component id= "password" type= "TextField">            value= "password" /> <binding name= "value" value= "password" />            value= " true " /> <binding name= "hidden" value= "true" />       </ component>   </ page-specification> 

First of all we see is a username and password both the definition of property, and Tapestry3 difference is that now Tapestry4.0 do not need to specify the type of property, that is to say, Tapestry4.0 based on the actual run-time program loaded onto the property automatically converted to the corresponding data type.

In java, we have two property declarations of the abstract method call:

  public abstract String  getUsername(); / / User name public abstract String getUsername ();   public abstract String  getPassword(); / / Password public abstract String getPassword (); 

Since we abstract method declaration is the type String, so even if not stated in page two property types, Tapestry4.0 also be able to know that they are String.

Here, let us run around on the Tapestry has a preliminary understanding of the mechanism. Page document in the definition of property on the equivalent page in the java class member variable definition. We can understand the image, the actual operation in the Tapestry framework, it will automatically type your page to generate a subclass subclass, and in accordance with the definition page in the property automatically added to the standard JavaBean. Of course, this is just a image understanding, because the Tapestry is by scanning a document and apply xml to achieve the whole process of reflection, and not really to generate a subclass. Likely to have friends ask: "If we do not type in the declaration page of the abstract property corresponding getter / setter methods, then Tapestry will not know what type of property then in the end?" The whole fair question, we know that in java in Object is any object of the subclass. In fact, if your property declaration in the logic of the entire page, there is no place to call, then Tapestry is not actually concerned about this specific type of property. The reason why we in the java category page to add the abstract getter / setter methods, because we actually need to type in the page get / set the property value.

So, if our property and java page class definition of a JavaBean are the same name, what would happen? Oh, the answer is that Tapestry will be error. It should be noted that, although the property of the JavaBean and standards have the same effect, but to write the page class JavaBean, the corresponding getter / setter methods must be to write the whole (if the page does not call the logic of its getter / setter methods, you can not write ).

OK, let us continue, we stated in the page three components:

   type= "Form" > <component id= "loginForm" type= "Form">            value= "listener:loginSubmit" /> <binding name= "listener" value= "listener:loginSubmit" />   </ component>    type= "TextField" > <component id= "username" type= "TextField">            value= "username" /> <binding name= "value" value= "username" />   </ component>    type= "TextField" > <component id= "password" type= "TextField">            value= "password" /> <binding name= "value" value= "password" />            value= " true " /> <binding name= "hidden" value= "true" />    </ component> 

Form component of the mechanism is too complex, we leave to the future in depth. TextField component, we can be understood as such a process: When the Tapestry framework jwcid found on the page, it will be in accordance with its type to trigger the corresponding components called html, jwc and java, we have regardless of the realization of the principle of just writing a preliminary understanding to do and see TextField component to the final page of static HTML display of what to write. TextField components such as the above two:

   id= "username"  value=""/> <input type= "text" id= "username" value=""/>    id= "password"  value=""/> <input type= "password" id= "password" value=""/> 

Oh, here, we can experience it is obvious that the so-called Tapestry component-oriented way of thinking. The same components, id = "username" and id = "password" to quote the two pairs of components, only the parameters of the different components will automatically generate a different HTML tags. Tapestry-oriented components in the way of thinking, the components like a "black box", as a component of the user, we do not need to care about this "black box" of concrete structures. Any user, as long as the components of the same set of parameters, components will accomplish the same function. Therefore, Tapestry components for their own thinking, in essence, reached the "accumulation of" objective.

For Home.html we read as follows:

  <html>   <body>    border= "1" > <table width= "33%" border= "1">     > <form jwcid= "loginForm">     <tr>        align= "center" ></td> <td width= "32%" align= "center"> Sign In </ td>        align= "center"  valign= "middle" >&nbsp;</td> <td width= "68%" align= "center" valign= "middle"> </ td>     </ tr>     <tr>        align= "left" >:</td> <td width= "32%" align= "left"> Username: </ td>        align= "left" ><input type= "text"  jwcid= "username" /></td> <td width= "68%" align= "left"> <input type= "text" jwcid= "username" /> </ td>     </ tr>     <tr>       >:</td> <td align= "left"> Password: </ td>       ><input type= "password"  jwcid= "password" /></td> <td align= "left"> <input type= "password" jwcid= "password" /> </ td>     </ tr>     <tr>       >&nbsp;</td> <td align= "left"> </ td>       ><input type= "submit"  value= "" /></td> <td align= "center"> <input type= "submit" value= "" /> </ td>     </ tr>     </ form>   </ table>   </ body>   </ html> 

Html embedded in jwcid with the same Tapestry3.0, but the only difference is that in Tapestry4.0 in, "jwcid" the term for you can modify any of the words specified.

Now, open the server, start the project, we will see a form page:

Then we enter the user name and password, you can see the eclipse console print out the corresponding value:

In fact, a closer look at the monitor loginSubmit of Home.java method IRequestCycle parameters we do not use, so that the monitor can be simple as:

  public  void loginSubmit() { / / Login form of monitoring methods public void loginSubmit () (       .out.println( this .getUsername()); System. Out.println (this. GetUsername ());       .out.println( this .getPassword()); System. Out.println (this. GetPassword ());   ) 

In Tapestry3.0, the monitoring method must be fixed format public void listenerMethod (IRequestCycle cycle) (), but Tapestry4.0, the monitoring method has become very flexible format. Cart in the whole sample, we will see a variety of monitoring methods format.

Now, we increase the effectiveness of some form, for example, our client requested a user name and password-tested, they must enter, and the password must be greater than 6 characters, so Home.page modify the Form and TextField components components statement as follows:

   type= "Form" > <component id= "loginForm" type= "Form">            value= "listener:loginSubmit" /> <binding name= "listener" value= "listener:loginSubmit" />            value= " true " /> <binding name= "clientValidationEnabled" value= "true" />   </ component>    type= "TextField" > <component id= "username" type= "TextField">            value= "username" /> <binding name= "value" value= "username" />            value= "validators:required" /> <binding name= "validators" value= "validators:required" />              value= "literal:【】" /> <binding name= "displayName" value= "literal:【】" />   </ component>    type= "TextField" > <component id= "password" type= "TextField">            value= "password" /> <binding name= "value" value= "password" />            value= " true " /> <binding name= "hidden" value= "true" />            value= "validators:required,minLength=6" /> <binding name= "validators" value= "validators:required,minLength=6" />            value= "literal:【】" /> <binding name= "displayName" value= "literal:【】" />   </ component> 

After running the project, we suddenly find the following pages:

Tapestry4 page from the error, we found that once added to the TextField client-tested, it is necessary to run the components of the Body, then we in the <body> Tags Home.html add Body Components:

  > <body jwcid= "@Body"> 

Another visit to Home page, OK, everything will be all right:


Perhaps you find it very strange that we do not have to write any javascript code, how are we going to complete the JavaScript client-tested it? Tapestry component that is the charm of a dynamic script. Here we use the Form component, in Tapestry4.0 in, Form dynamic components, bringing a number of script code, regardless of Form component in any case the use of any project, as long as the open

   value= " true " /> <binding name= "clientValidationEnabled" value= "true" /> 

JavaScript can be achieved efficacy. Tapestry components like a black box, dynamic script like a piece of the box we do not need to understand the JavaScript code, as long as we pressed the "box" a "switch", dynamic Script will be automatically generated through the Tapestry framework to adapt to the current form of JavaScript code. Therefore, even if not this Dynamic Script I wrote it myself, we can also be used with impunity.

Oh, we have completed the landing page. Perhaps the first contact with Tapestry, skull is full of exclamation points and question marks? There may be a little ellipsis? However, no relationship, let us continue the example to understand Cart Tapestry. Decompositionnext time ~


tapestry & hivemind Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.