KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > madvoc > HelloAction


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package madvoc;
4
5 import jodd.madvoc.interceptor.ScopeType;
6 import jodd.madvoc.meta.*;
7 import jodd.mutable.MutableInteger;
8 import jodd.petite.meta.PetiteBeanRef;
9
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import madvoc.biz.FooService;
16
17 /**
18  * Default usage.
19  */

20 @MadvocAction
21 @InterceptedBy(MyInterceptorStack.class)
22 public class HelloAction {
23
24     // ---------------------------------------------------------------- 1
25

26     @In
27     private String JavaDoc name;
28     public void setName(String JavaDoc name) {
29         this.name = name + "xxx";
30     }
31
32     @In
33     MutableInteger data;
34
35     @Out
36     String JavaDoc retv;
37
38     @PetiteBeanRef
39     FooService fooService; // example of using petite container
40

41
42     /**
43      * Action mapped to '/hello.world.html'
44      * Result mapped to '/hello.world.ok.jsp'
45      */

46     public String JavaDoc world() {
47         System.out.println(">HelloAction.world " + name + data);
48         retv = " and Universe";
49         fooService.hello();
50         return "ok";
51     }
52
53     // ---------------------------------------------------------------- 2
54

55     @In("p")
56     Person person; // Due to create == true, person will be instanced on first access.
57

58     /**
59      * Action mapped to '/hello.all.html'
60      * Result mapped to '/hello.all.jsp' and aliased to /hi-all.jsp
61      */

62     public String JavaDoc all() {
63         System.out.println(">HelloAction.all " + person);
64         return "";
65     }
66
67     // ---------------------------------------------------------------- 3
68

69     @In("ppp")
70     List JavaDoc<Person> plist;
71
72     @In("ppp")
73     Person[] parray;
74
75     @In("ppp")
76     Map JavaDoc<String JavaDoc, Person> pmap;
77
78     @In(scope=ScopeType.CONTEXT)
79     HttpServletResponse JavaDoc servletResponse;
80
81     /**
82      * Action mapped to '/hello.again.html'
83      * No result.
84      */

85     public String JavaDoc again() throws IOException JavaDoc {
86         System.out.println(">HelloAction.again");
87
88         if (plist == null) {
89             System.out.println("-");
90         } else {
91             for (int i = 0; i < plist.size(); i++) {
92                 System.out.println(i + " " + plist.get(i));
93             }
94         }
95
96         if (parray == null) {
97             System.out.println("-");
98         } else {
99             for (int i = 0; i < parray.length; i++) {
100                 System.out.println(i + " " + parray[i]);
101             }
102         }
103
104         if (pmap == null) {
105             System.out.println("-");
106         } else {
107             System.out.println(pmap);
108         }
109
110
111         servletResponse.getWriter().print("Direct stream output...");
112         return null;
113     }
114
115     // ---------------------------------------------------------------- 4
116

117     /**
118      * Forward.
119      */

120     public String JavaDoc fff() {
121         System.out.println(">HelloAction.fff");
122         return "forward:/hello.again.html";
123     }
124 }
125
Popular Tags