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.Artist; 8 9 14 public abstract class AddArtistPage extends EditorPage { 15 16 public abstract void setArtist(Artist value); 19 public abstract Artist getArtist(); 20 21 public void saveArtistAction(IRequestCycle cycle) { 22 DataContext context = getVisitDataContext(); 23 24 Artist artist = getArtist(); 26 27 if (!assertNotNull(artist.getArtistName())) { 28 appendHtmlToErrorMessage("You must provide a name."); 29 } 30 31 if (!assertNotNull(artist.getDateOfBirth())) { 32 appendHtmlToErrorMessage("You must provide a DOB."); 33 } 34 35 if (getHasErrorMessage()) { 36 return; 37 } 38 39 context.registerNewObject(artist); 41 42 context.commitChanges(); 44 45 BrowseArtistsPage nextPage = 46 (BrowseArtistsPage) cycle.getPage("BrowseArtistsPage"); 47 48 if (nextPage.getArtistList() != null) { 51 nextPage.getArtistList().add(artist); 52 } 53 54 cycle.activate(nextPage); 55 } 56 57 public void pageBeginRender(PageEvent event) { 58 setArtist(new Artist()); 64 } 65 } 66 | Popular Tags |