struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Miles" <ch...@chrismiles.org>
Subject Re: Nested Iterator Problem
Date Sat, 03 Jul 2010 10:23:38 GMT
Hi,

Thanks. My action class is as follows. It is very basic. The confusion is 
that I can call a property once but it fails as soon as I try to even call 
the same property a second time. It is beyond reasoning.

Chris

package sentiments.struts2.checkout;

import sentiments.struts2.ShopAction;
import sentiments.business.service.ShopService;
import sentiments.business.domain.cart.Item;
import sentiments.business.domain.cart.Order;
import sentiments.business.domain.PersonalDetails;
import sentiments.business.domain.Product;

import javax.ejb.EJB;
import java.util.List;
import java.util.Calendar;
import java.util.ArrayList;

import com.opensymphony.xwork2.Action;

public class ProcessOrderAction extends ShopAction {
    @EJB
    private ShopService shopService;
    private Order order;
    private List<Item> items;
    private List<PersonalDetails> shippingDetails;

    public void prepare() throws Exception {
        this.items = this.getCartMgr().getItems();
        this.shippingDetails = buildUniqueShippingDetails();
        attachItemsToShippingDetails();
    }

    private void attachItemsToShippingDetails() {
        for (PersonalDetails shippingDetails : this.shippingDetails) {
            List<Product> products = new ArrayList<Product>();
            // For each item in the cart.
            for (Item item : this.items) {
                // If this item is being sent to that shipping address.
                if (item.getShippingDetails().equals(shippingDetails)) {
                    products.add(item.getProduct());
                }
            }
            // Attach the products.
            shippingDetails.setProducts(products);
        }
    }

    private List<PersonalDetails> buildUniqueShippingDetails() {
        List<PersonalDetails> personalDetailses =
                new ArrayList<PersonalDetails>();

        for (Item item : this.items) {
            PersonalDetails existingShippingDetails = 
item.getShippingDetails();
            if (existingShippingDetails != null
                    && !personalDetailses.contains(existingShippingDetails)) 
{
                personalDetailses.add(existingShippingDetails);
            }
        }
        return personalDetailses;
    }

    public String confirmOrderDetails() throws Exception {
        this.addActionMessage("Please confim your order. Once you place the 
order payment will be taken.");
        return Action.SUCCESS;
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }

    public List<PersonalDetails> getShippingDetails() {
        return shippingDetails;
    }

    public void setShippingDetails(List<PersonalDetails> shippingDetails) {
        this.shippingDetails = shippingDetails;
    }
}

----- Original Message ----- 
From: "Ken" <ken.mcwilliams@aerose.com>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Thursday, July 01, 2010 10:46 PM
Subject: Re: Nested Iterator Problem


> His editor should be fine with Unicode... hmm, post your action bean.
>
> On Thu, 2010-07-01 at 14:30 -0700, Chris Pratt wrote:
>
>> On my screen it looks like there's a British pound sign in the text, 
>> which I
>> believe is outside the ASCII characters set, I'm just wondering if that
>> could be causing the trouble.  It's definitely something I've never tried
>> myself.
>>   (*Chris*)
>
>
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message