Generic type List shows same value each time in PrimeFaces datatable in spring framework. I add component to the List by looping

Viewed 77

When I want to show data in datatable through getListPortfolio() method it shows lastly added value for many times.

This is my ManageBean where method is created. Codes are Following.

@Controller
@ManagedBean
@SessionScoped
@Transactional

public class MbPortfolio {

    @Autowired
    Portfolio portfolio;

    @Autowired
    TransactionService transactionService;

    public Portfolio getPortfolio() {
        return portfolio;
    }

    public void setPortfolio(Portfolio portfolio) {
        this.portfolio = portfolio;
    }

    public TransactionService getTransactionService() {
        return transactionService;
    }

    public void setTransactionService(TransactionService transactionService) {
        this.transactionService = transactionService;
    }

    public List<Portfolio> getListPortfolio() {
        List <Transaction> lst = transactionService.clientPortfolio();
        System.out.println(lst.size()+ "lkdlkdkgfkldglkfkljfljklkgfl");
        List <Portfolio> lst2=new ArrayList<Portfolio>();

        for (int i = 0; i < lst.size(); i++) {
            portfolio.setShareCode(lst.get(i).getClient().getClientName());
            lst2.add(portfolio);
        }
        return lst2;

    }
}

And here is my Portfolio class.

public class Portfolio  extends Transaction implements java.io.Serializable {

    private String shareCode;
    private Double shareAmount;
    private Double shareCostPrice;
    private Double shareTotalCostPrice;
    private Double shareMarketPrice;
    private Double shareTotalMarketPrice;

    public Portfolio() {
    }

    public Portfolio(String shareCode, Double shareAmount, Double shareCostPrice, Double shareTotalCostPrice, Double shareMarketPrice, Double shareTotalMarketPrice) {
        this.shareCode = shareCode;
        this.shareAmount = shareAmount;
        this.shareCostPrice = shareCostPrice;
        this.shareTotalCostPrice = shareTotalCostPrice;
        this.shareMarketPrice = shareMarketPrice;
        this.shareTotalMarketPrice = shareTotalMarketPrice;
    }

    public String getShareCode() {
        return shareCode;
    }

    public void setShareCode(String shareCode) {
        this.shareCode = shareCode;
    }

    public Double getShareAmount() {
        return shareAmount;
    }

    public void setShareAmount(Double shareAmount) {
        this.shareAmount = shareAmount;
    }

    public Double getShareCostPrice() {
        return shareCostPrice;
    }

    public void setShareCostPrice(Double shareCostPrice) {
        this.shareCostPrice = shareCostPrice;
    }

    public Double getShareTotalCostPrice() {
        return shareTotalCostPrice;
    }

    public void setShareTotalCostPrice(Double shareTotalCostPrice) {
        this.shareTotalCostPrice = shareTotalCostPrice;
    }

    public Double getShareMarketPrice() {
        return shareMarketPrice;
    }

    public void setShareMarketPrice(Double shareMarketPrice) {
        this.shareMarketPrice = shareMarketPrice;
    }

    public Double getShareTotalMarketPrice() {
        return shareTotalMarketPrice;
    }

    public void setShareTotalMarketPrice(Double shareTotalMarketPrice) {
        this.shareTotalMarketPrice = shareTotalMarketPrice;
    }

}

It shows lastly added name for many times. please help me.

1 Answers
Related