You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by ael <al...@dash.com.ph> on 2010/10/22 10:34:41 UTC

T5 Guide: Working Shopping Cart. Feel Free to comment...

This is my shopping cart using SSO.

TbCart.Class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dash.ssocart.entities;

/**
 *
 * @author alan
 */
public class TbCart implements java.io.Serializable {

    private String items;

    public TbCart() {
    }

    public TbCart(String items) {
        this.items = items;
    }

    public String getItems() {
        return items;
    }

    public void setItems(String items) {
        this.items = items;
    }
}



UserSession.Class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dash.ssocart.sso;

import com.dash.ssocart.entities.TbCart;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author alan
 */
public class UserSession {

   private List<TbCart> tbcart = new ArrayList<TbCart>();
   private TbCart items;

    public List<TbCart> getTbcart() {
        return tbcart;
    }

    public void setTbcart(List<TbCart> tbcart) {
        this.tbcart = tbcart;
    }

    public TbCart getItems() {
        return items;
    }

    public void setItems(TbCart items) {
        this.items = items;
        tbcart.add(items);
    }    
}



Index.java

package com.dash.ssocart.pages;

import com.dash.ssocart.entities.TbCart;
import com.dash.ssocart.sso.UserSession;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;

/**
 * Start page of application SSOCart.
 */
public class Index
{
    @SessionState
    @Property
    private UserSession usersession;
    private boolean usersessionExists;

    Object onActivate(){
        
        // Create New Cart Items
        TbCart c = new TbCart("Tapestry Book");

        usersession.setItems(c);
    
        return null;
    }
}



About.java

package com.dash.ssocart.pages;

import com.dash.ssocart.entities.TbCart;
import com.dash.ssocart.sso.UserSession;
import java.util.List;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;

public class About
{

    @SessionState
    @Property
    private UserSession usersession;
    private boolean usersessionExists;


    public List<TbCart> getCart(){
        
        return usersession.getTbcart();
    }

}
    


About.tml

        <p>
             <t:grid source="Cart"/>
        </p>


Practice made perfect...
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Guide-Working-Shopping-Cart-Feel-Free-to-comment-tp3231907p3231907.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org