KickJava   Java API By Example, From Geeks To Geeks.

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


1 package cayenne.tutorial.tapestry.pages;
2
3 import org.apache.tapestry.IRequestCycle;
4 import org.apache.tapestry.event.PageEvent;
5 import org.objectstyle.cayenne.access.DataContext;
6
7 import cayenne.tutorial.tapestry.domain.Gallery;
8
9 /**
10  * A page to add new Art Galleries to the system.
11  *
12  * @author Eric Schneider
13  */

14 public abstract class AddGalleryPage extends EditorPage {
15
16     // properties are defined as abstract setters and getters
17
// and are declared in AddGalleryPage.page file
18
public abstract void setGallery(Gallery value);
19     public abstract Gallery getGallery();
20
21     public void saveGalleryAction(IRequestCycle cycle) {
22         Gallery gallery = getGallery();
23
24         if (!assertNotNull(gallery.getGalleryName())) {
25             appendHtmlToErrorMessage("You must provide a gallery name.");
26             return;
27         }
28
29         DataContext ctxt = getVisitDataContext();
30         ctxt.registerNewObject(gallery);
31
32         // commit to the database
33
ctxt.commitChanges();
34
35         BrowseGalleriesPage nextPage =
36             (BrowseGalleriesPage) cycle.getPage("BrowseGalleriesPage");
37
38         // update the next page if it has cached galleries
39
// to avoid unneeded refreshing
40
if (nextPage.getGalleryList() != null) {
41             nextPage.getGalleryList().add(gallery);
42         }
43
44         cycle.activate(nextPage);
45     }
46
47     public void pageBeginRender(PageEvent event) {
48
49         // create new Gallery when page is initialized.
50
// Do not intsert it into DataContext just yet.
51
// Instead if we register it here, and the user abandons
52
// the page, we will have to find a way to rollback the context,
53
// to avoid grabage carried over to other pages
54
setGallery(new Gallery());
55     }
56
57 }
58
Popular Tags