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 14 public abstract class AddGalleryPage extends EditorPage { 15 16 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 ctxt.commitChanges(); 34 35 BrowseGalleriesPage nextPage = 36 (BrowseGalleriesPage) cycle.getPage("BrowseGalleriesPage"); 37 38 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 setGallery(new Gallery()); 55 } 56 57 } 58 | Popular Tags |