KickJava   Java API By Example, From Geeks To Geeks.

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


1 package cayenne.tutorial.tapestry.pages;
2
3 import java.math.BigDecimal JavaDoc;
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 /**
13  * Page to create a new Painting record, adding it to selected artist.
14  *
15  * @author Eric Schneider
16  */

17 public abstract class AddPaintingPage extends EditorPage {
18
19     // properties are defined as abstract setters and getters
20
// and are declared in AddPaintingPage.page file
21
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         // painting was created earlier, but before we can
39
// start working with its relationships, and ultimately
40
// save it to DB, it must be regsitered with DataContext
41
ctxt.registerNewObject(painting);
42
43         // establish relationship with artist via a simple method call
44
// an equivalent of the line below would be "
45
artist.addToPaintingArray(painting);
46
47         // commit to the database
48
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 JavaDoc(0));
59         setPainting(painting);
60     }
61 }
62
Popular Tags