Java Reference
In-Depth Information
private String description;
private String image;
// simple setters and getters
…
Now that we have our domain classes set up, let's tackle the presentation bean.
Looking at the
CatalogBean
presentation class (listing 14.9) will provide our first
glimpse at how the
BeanAction
functions in the real world. We need to create the
CatalogBean
with a
viewCategory
behavior. The behavior method will use the
BeanAction
style behavior signature of
public
String
<behaviorName>
()
. The
viewCategory
behavior is quite simple. Its job is to retrieve a list of products that
are related to the selected category, fully populate the
Category
object, and then
forward to a view. In the body of our
viewCategory
method, the
productList
and
the
categoryList
are populated by making calls to the
CatalogService
class. We
will get into the service class later. For now, suffice it to say we'll assume that the
service class will return our objects appropriately.
Listing 14.9
CatalogBean presentation class with properties and viewCategory Behavior
…
private String categoryId;
private Category category;
…
private PaginatedList productList;
…
public String viewCategory() {
if (categoryId != null) {
productList =
catalogService.getProductListByCategory(categoryId);
category = catalogService.getCategory(categoryId);
}
return SUCCESS;
}
…
// category setter/getter
…
// productList setter/getter
…
To get the
CatalogBean
to compile, we'll create a simple
CatalogService
interface
in the org.apache.ibatis.jgamestore.service package. We'll add two necessary meth-
ods—
public
List
getProductListByCategory(Integer
categoryId)
and
public















