KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cayenne > tutorial > tapestry > pages > BrowseGalleriesPage


1 package cayenne.tutorial.tapestry.pages;
2
3 import java.util.List JavaDoc;
4
5 import org.apache.tapestry.IRequestCycle;
6 import org.apache.tapestry.event.PageEvent;
7 import org.objectstyle.cayenne.query.Ordering;
8 import org.objectstyle.cayenne.query.SelectQuery;
9
10 import cayenne.tutorial.tapestry.domain.Gallery;
11 import cayenne.tutorial.tapestry.domain.Painting;
12
13 /**
14  * Page displaying galleries with their paintings.
15  *
16  * @author Eric Schneider
17  */

18 public abstract class BrowseGalleriesPage extends ApplicationPage {
19
20     // properties are defined as abstract setters and getters
21
// and are declared in BrowseGalleriesPage.page file
22
public abstract void setGallery(Gallery value);
23     public abstract Gallery getGallery();
24
25     public abstract void setPainting(Painting value);
26     public abstract Painting getPainting();
27
28     public abstract void setGalleryList(List JavaDoc value);
29     public abstract List JavaDoc getGalleryList();
30
31     public void removePaintingAction(IRequestCycle cycle) {
32         getGallery().removeFromPaintingArray(getPainting());
33
34         // commit to the database
35
getVisitDataContext().commitChanges();
36     }
37
38     public void pageBeginRender(PageEvent event) {
39         // fetch the galleries if we do not have them cached
40
if (getGalleryList() == null) {
41             SelectQuery query = new SelectQuery(Gallery.class);
42             query.addOrdering(new Ordering(Gallery.GALLERY_NAME_PROPERTY, Ordering.ASC));
43
44             // prefetch paintings and artist, since they are displayed on the screen
45
// this should improve performance
46
query.addPrefetch(Gallery.PAINTING_ARRAY_PROPERTY);
47             query.addPrefetch(
48                 Gallery.PAINTING_ARRAY_PROPERTY + "." + Painting.TO_ARTIST_PROPERTY);
49
50             setGalleryList(getVisitDataContext().performQuery(query));
51         }
52     }
53 }
54
Popular Tags