1 package cayenne.tutorial.tapestry.pages; 2 3 import java.math.BigDecimal ; 4 5 import org.apache.tapestry.IRequestCycle; 6 import org.apache.tapestry.event.PageEvent; 7 import org.objectstyle.cayenne.access.DataContext; 8 9 import cayenne.tutorial.tapestry.domain.Artist; 10 import cayenne.tutorial.tapestry.domain.Painting; 11 12 17 public abstract class AddPaintingPage extends EditorPage { 18 19 public abstract void setArtist(Artist value); 22 public abstract Artist getArtist(); 23 24 public abstract void setPainting(Painting value); 25 public abstract Painting getPainting(); 26 27 public void savePaintingAction(IRequestCycle cycle) { 28 Painting painting = getPainting(); 29 Artist artist = getArtist(); 30 31 if (!assertNotNull(painting.getPaintingTitle())) { 32 appendHtmlToErrorMessage("You must provide a painting title."); 33 return; 34 } 35 36 DataContext ctxt = getVisitDataContext(); 37 38 ctxt.registerNewObject(painting); 42 43 artist.addToPaintingArray(painting); 46 47 ctxt.commitChanges(); 49 50 BrowseArtistsPage nextPage = 51 (BrowseArtistsPage) cycle.getPage("BrowseArtistsPage"); 52 53 cycle.activate(nextPage); 54 } 55 56 public void pageBeginRender(PageEvent event) { 57 Painting painting = new Painting(); 58 painting.setEstimatedPrice(new BigDecimal (0)); 59 setPainting(painting); 60 } 61 } 62 | Popular Tags |