01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: Add.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package tutorial.friends;
09:
10: import com.uwyn.rife.engine.Element;
11: import com.uwyn.rife.site.Validated;
12: import com.uwyn.rife.template.Template;
13: import tutorial.friends.backend.Friend;
14: import tutorial.friends.backend.FriendManager;
15:
16: /**
17: * Adds a new <code>Friend</code> to the database.
18: *
19: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
20: * @version $Revision: 3634 $
21: */
22: public class Add extends Element {
23: /**
24: * The element's entry point.
25: */
26: public void processElement() {
27: Template template = getHtmlTemplate("add");
28:
29: // only if friend data has been submitted, add it to the database
30: Friend friend = (Friend) getNamedSubmissionBean("friend_data",
31: "friend");
32: if (friend != null) {
33: // check the validity of the bean
34: if (!((Validated) friend).validate()) {
35: generateForm(template, friend);
36: } else {
37: // obtain the manager of the bean
38: FriendManager manager = new FriendManager();
39: // add the new friend
40: manager.add(friend);
41: template.setBlock("content", "content_added");
42: }
43: }
44:
45: print(template);
46: }
47: }
|