Tutorials to .com

Tutorials to .com » Jsp » Tapestry-hivemind » 2 Cart tapestry, fruit shop

2 Cart tapestry, fruit shop

Print View , by: iSee ,Total views: 11 ,Word Count: 1586 ,Date: Thu, 16 Apr 2009 Time: 4:50 AM

OK, now landing has been achieved, we are now for the "shopping cart" to add some commodities, the assumption that we are all fruit:
Our definition of an ordinary fruit VO:

   com.tapestry4; package com.tapestry4;    class Fruit { public class Fruit (           Integer  id; private Integer id;           String  name; //  private float  price; //  private int  mount; //  public int  getMount() { private String name; / / Name private float price; / / Price private int mount; / / the number of public int getMount () (                    mount; return mount;           )            void setMount( int  mount) { public void setMount (int mount) (                   .mount = mount; this. mount = mount;           )           String  getName() { public String getName () (                    name; return name;           )            void setName( String  name) { public void setName (String name) (                   .name = name; this. name = name;           )           float  getPrice() { public float getPrice () (                    price; return price;           )            void setPrice( float  price) { public void setPrice (float price) (                   .price = price; this. price = price;           )           Integer  getId() { public Integer getId () (                    id; return id;           )            void setId( Integer  id) { public void setId (Integer id) (                   .id = id; this. id = id;           )   ) 

And then the logic of the definition of a commodity business categories:

   com.tapestry4; package com.tapestry4;    java.util.ArrayList; import java.util.ArrayList;    java.util.List; import java.util.List;    class Products { public class Products (            List<Fruit> productList; private static List <Fruit> productList;            List<Fruit> getProductList() { public static List <Fruit> getProductList () (                   (productList== null ) { if (productList == null) (                            ArrayList<Fruit>(); productList = new ArrayList <Fruit> ();                           , 1.00f, 20)); productList.add (createFruit (1, "Apple", 1.00f, 20));                           , 0.80f, 10)); productList.add (createFruit (2, "Watermelon", 0.80f, 10));                           , 1.50f, 25)); productList.add (createFruit (3, "orange", 1.50f, 25));                           , 2.00f, 30)); productList.add (createFruit (4, "pears", 2.00f, 30));                   )                    productList; return productList;           )            Fruit createFruit( Integer  ig, String  name, float  price, int  mount) { public static Fruit createFruit (Integer ig, String name, float price, int mount) (                    Fruit(); Fruit fruit = new Fruit ();                   fruit.setId (ig);                   fruit.setName (name);                   fruit.setPrice (price);                   fruit.setMount (mount);                    fruit; return fruit;           )            Fruit findFruitById( Integer  ig) { public static Fruit findFruitById (Integer ig) (                   (productList == null ) { if (productList == null) (                           productList = getProductList ();                   )                   ; Fruit fruit = null;                   (Fruit f : productList) { for (Fruit f: productList) (                           (f.getId().intValue() == ig.intValue()) { if (f.getId (). intValue () == ig.intValue ()) (                                   fruit = f;                           )                   )                    fruit; return fruit;           )   ) 

Now, we need a page to display goods, named Shop:

  Shop.java    com.tapestry4; package com.tapestry4;    java.util.List; import java.util.List;    org.apache.tapestry.html.BasePage; import org.apache.tapestry.html.BasePage;    class Shop extends  BasePage { public class Shop extends BasePage (            List getFruitList() { public List getFruitList () (                    Products.getProductList(); return Products.getProductList ();           )   ) 
  Shop.page   <page-specification>       /> <property name= "fruit" />        type= "Foreach" > <component id= "fruitListLoop" type= "Foreach">            value= "fruitList" /> <binding name= "source" value= "fruitList" />            value= "fruit" /> <binding name= "value" value= "fruit" />            value= "literal:tr" /> <binding name= "element" value= "literal:tr" />       </ component>        type= "Insert" > <component id= "fruitName" type= "Insert">            value= "fruit.name" /> <binding name= "value" value= "fruit.name" />       </ component>        type= "Insert" > <component id= "fruitPrice" type= "Insert">            value= "fruit.price" /> <binding name= "value" value= "fruit.price" />       </ component>   </ page-specification> 
  Shop.html   <html>   <body>    border= "1" > <table width= "419" border= "1">     > <tr align= "center">       ></td> <td width= "240"> fruit name </ td>       ></td> <td width= "139"> Price </ td>     </ tr>      align= "center" > <tr jwcid= "fruitListLoop" align= "center">       ></span></td> <td> <span jwcid= "fruitName"> name </ span> </ td>       ></span></td> <td> <span jwcid= "fruitPrice"> Price </ span> element </ td>     </ tr>   </ table>   </ body>   </ html> 

In order to be able to visit the following page Jump to Catalog Shop, we need to modify Home.java:

   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 (); 		  ) @ 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 (); 	  )   ) 

Attention to methods of monitoring the return loginSubmit parameters, where a direct return to the examples page can Shop Jump to Shop page. @ InjectPage ( "Shop") is a new Tapestry4.0 provided an annotation package annotation. Any statement by the annotation of the abstract getter methods will be available to the instance of the specified page. Here access to the Shop page on the examples.

In the Enter the user name and password, we can jump to a new page of:


tapestry & hivemind Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.