What Would the Trasfer Object Look Like if I Have a List of Objects?

What would the "transfer object" look like If I have a List of objects and each object has its properties? Do I have a HashSet in my transfer object?

To clarify my question, let me give an example.

Say, I have a store and I sell music CDs. Each CD has composer, title, and price as its properties. How do I code the transfer object to pass data between J2EE tiers?

In my JSF backing bean, I have java.util.List and I use DataModel to display all CDs in tabulation:

import java.util.ArrayList;

import java.util.List;

import javax.faces.model.DataModel;

import javax.faces.model.ListDataModel;

publicclass CDManagerBean

{

private String title;

private Float price;

private String artist;

private List cds =new ArrayList();

private DataModel cdModel =new ListDataModel();

{

cdModel.setWrappedData(cds);

}

// getters and setters

// addCD(), editCD(), and updateCD() methods

}

I also have a CD java class:

publicclass CDimplements java.io.Serializable

{

private String title;

private String artist;

privatefloat price;

public CD(){}

// getters and setters

}

[2235 byte] By [jiapei_jena] at [2007-11-15]
# 1
Given that your CD class is simply a collection of properties and is Serializable, I would simply pass a List<CD> between the tiers.
RaymondDeCampoa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2
The CD itself is per definition the Data Transfer Object (DTO). The List<CD> is a collection of DTO's.
BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3

In fact, I did not give an appropriate example to illustrate the real situation I have to handle. I cannot show my real code because I work on a project that requires security clearance.

My backing bean should not be named as CDManagerBean. Instead, I should have named it as StoreManagerBean. In the StoreManagerBean, I have many store-related properties. And

jave.util.List cds;

is one of the properties.Of course, each CD has its own properties.

How should I code my transfer object to transport data between tiers from the front-end to the back-end and from the back-end to the front-end?

Thank you for guidance.

jiapei_jena at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
You don't need add this logic to the DTO. A DTO should be just a simple mapping of a database table and/or a presentation of the webapplication.The logic to handle DTO's should be inside the backing bean (towards the presentation layer) and the DAO (towards the database).
BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...