Tutorials to .com

Tutorials to .com » Jsp » Tapestry-hivemind » 5 Cart tapestry, let us try to do some small

5 Cart tapestry, let us try to do some small

Print View , by: iSee ,Total views: 9 ,Word Count: 1748 ,Date: Thu, 16 Apr 2009 Time: 9:01 PM

tapestry of the annotation

In Tapestry4.0, the introduction of a separate function: JDK 5's annotation. However, Tapestry is JDK version support more than jdk1.3, so even if the non-use of JDK 5, do not use Tapestry annotation package can be developed to achieve the same effect.

For example:

  ) @ InjectPage ( "Shop")    Shop getShopPage(); public abstract Shop getShopPage (); 

@ InjectPage here by way of a declaration of the annotation, Tapestry in the reflex to getShopPage () method abstract when you name a page "Shop" page of the instance of a class into account.
Therefore, having the same two ways for writing the following results:

  ) @ InjectPage ( "Shop")    Shop getShopPage(); public abstract Shop getShopPage ();   public  IPage loginSubmit(IRequestCycle cycle) { / / Login form method of monitoring public IPage loginSubmit (IRequestCycle cycle) (   .out.println( this .getUsername()); System. Out.println (this. GetUsername ());   .out.println( this .getPassword()); System. Out.println (this. GetPassword ());   .getShopPage(); return this. getShopPage ();   ) 
  public  IPage loginSubmit(IRequestCycle cycle) { / / Login form method of monitoring public IPage loginSubmit (IRequestCycle cycle) (           ); Shop page = (Shop) cycle.getPage ( "Shop");           .out.println( this .getUsername()); System. Out.println (this. GetUsername ());           .out.println( this .getPassword()); System. Out.println (this. GetPassword ());            page; return page;   ) 

Since then, I will try to in the document with the annotation given the same form. How you feel convenient, on how to use it.

Object on the session and application management

In the previous example, we will manage the session object to the visit, the visit object MyTapestry.application stated:

   value= "com.tapestry4.MyVisit" /> <meta key= "org.apache.tapestry.visit-class" value= "com.tapestry4.MyVisit" /> 

The page and then we can call to visit this object:

  .getVisit(); MyVisit visit = (MyVisit) this. GetVisit (); 

In addition, we can also annotation objects to a statement on the visit of the call:

  ) @ InjectState ( "visit")    MyVisit getMyVisit(); public abstract MyVisit getMyVisit (); 

If you do not use the annotation, can be stated in the page:

   type= "state"  object= "visit" /> <inject property= "myVisit" type= "state" object= "visit" /> 

Page and then continue to visit the abstract method to get the object.

For the management of session objects, Tapestry is a visit into an independent object, @ InjectState There are two default parameters, one visit, the other one is global, for access to global objects and objects visit.

For the management of application objects, Tapestry is on an independent global object, the object's use and visitthe same, different only in the life cycle of the object. Similarly, we can define its own global object, MyTapestry.application document in the statement:

   value= "com.tapestry4.MyGlobal" /> <meta key= "org.apache.tapestry.global-class" value= "com.tapestry4.MyGlobal" /> 

The use of FriendlyURL

In Tapestry4.0 use FriendlyURL very simple. In hivemodule.xml add:

  > <contribution configuration-id= "tapestry.url.ServiceEncoders">            stateless-extension= "direct"  stateful-extension= "sdirect" /> <direct-service-encoder id= "direct" stateless-extension= "direct" stateful-extension= "sdirect" />            extension= "page"  service= "page" /> <page-service-encoder id= "page" extension= "page" service= "page" />            extension= "external"  service= "external" /> <page-service-encoder id= "external" extension= "external" service= "external" />            path= "/assets/" /> <asset-encoder id= "asset" path= "/assets/" />   </ contribution> 

Stated in the web.xml:

  <servlet-mapping>           <servlet-name> MyTapestry4 </ servlet-name>           <url-pattern> *. page </ url-pattern>   </ servlet-mapping>   <servlet-mapping>           <servlet-name> MyTapestry4 </ servlet-name>           <url-pattern> *. external </ url-pattern>   </ servlet-mapping>   <servlet-mapping>           <servlet-name> MyTapestry4 </ servlet-name>           <url-pattern> *. direct </ url-pattern>   </ servlet-mapping>   <servlet-mapping>           <servlet-name> MyTapestry4 </ servlet-name>           <url-pattern> *. sdirect </ url-pattern>   </ servlet-mapping>   <servlet-mapping>           <servlet-name> MyTapestry4 </ servlet-name>           <url-pattern> / assets / * </ url-pattern>   </ servlet-mapping> 

The use of property in the page page with the java class the difference between the use of member variables

To Home page as an example, we can define the page in the property:

  > <property name= "username"> 

Tapestry framework will run automatically completed by the middle of the page type the following code:

  String  username; private String username;   @ Override    void initialize() { protected void initialize () (       .username= null ; this. username = null;   )   String  getUsername() { public abstract String getUsername () (        username; return username;   )    void setUsername( String  s) { public void setUsername (String s) (       username = s;   ) 

As a result, property and the page write the page written class member variables have the same effect, only in writing when the page member variable, do not forget to initialize () method to initialize member variables of, and to write full-getter / setter methods. For example:

  private String  password; / / Password private String password;   @ Override    void initialize() { protected void initialize () (           .password = null ; this. password = null;   )   String  getPassword() { public String getPassword () (            password; return password;   )    void setPassword( String  password) { public void setPassword (String password) (           .password = password; this. password = password;   ) 

If you need to initialize the page in the special value of property, you can:

   initial-value= "literal:" /> <property name= "username" initial-value= "literal:" /> 

Equivalent to the use of the annotation:

  ) @ InitialValue ( "literal: stir dry beans")   String  getUsername(); public abstract String getUsername (); 

If the statement of the annotation, you do not need to declare the property in the page.

Close Tapestry cache pool and improve development efficiency

Tapestry of the page cache has its own strategy. Once the page was the first visit, the page object will be loaded into the cache. Therefore, each of the HTML, page, or java changes will not take effect, you must restart the server. Development process in our time, so very inconvenient. Therefore, we can turn off the cache strategy for Tapestry, the time until the item is published, and then open.

In MyTapestry.application add:

   value= " true " /> <meta key= "org.apache.tapestry.disable-caching" value= "true" />    value= " true " /> <meta key= "org.apache.tapestry.enable-reset-service" value= "true" /> 

tapestry & hivemind Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.