001: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
002:
003: package madvoc;
004:
005: import jodd.madvoc.interceptor.ScopeType;
006: import jodd.madvoc.meta.*;
007: import jodd.mutable.MutableInteger;
008: import jodd.petite.meta.PetiteInject;
009:
010: import javax.servlet.http.HttpServletResponse;
011: import java.io.IOException;
012: import java.util.List;
013: import java.util.Map;
014:
015: import madvoc.biz.FooService;
016:
017: /**
018: * Default usage.
019: */
020: @MadvocAction
021: @InterceptedBy(MyInterceptorStack.class)
022: public class HelloAction {
023:
024: // ---------------------------------------------------------------- 1
025:
026: @In
027: private String name;
028:
029: public void setName(String name) {
030: this .name = name + "xxx";
031: }
032:
033: @In
034: MutableInteger data;
035:
036: @Out
037: String retv;
038:
039: @PetiteInject
040: FooService fooService; // example of using petite container
041:
042: /**
043: * Action mapped to '/hello.world.html'
044: * Result mapped to '/hello.world.ok.jsp'
045: */
046: public String world() {
047: System.out.println(">HelloAction.world " + name + data);
048: retv = " and Universe";
049: fooService.hello();
050: return "ok";
051: }
052:
053: // ---------------------------------------------------------------- 2
054:
055: @In("p")
056: Person person; // Due to create == true, person will be instanced on first access.
057:
058: /**
059: * Action mapped to '/hello.all.html'
060: * Result mapped to '/hello.all.jsp' and aliased in configuration to /hi-all.jsp
061: */
062: public String all() {
063: System.out.println(">HelloAction.all " + person);
064: return "";
065: }
066:
067: // ---------------------------------------------------------------- 3
068:
069: @In("ppp")
070: List<Person> plist;
071:
072: @In("ppp")
073: Person[] parray;
074:
075: @In("ppp")
076: Map<String, Person> pmap;
077:
078: @In(scope=ScopeType.CONTEXT)
079: HttpServletResponse servletResponse;
080:
081: /**
082: * Action mapped to '/hello.again.html'
083: * No result.
084: */
085: public String again() throws IOException {
086: System.out.println(">HelloAction.again");
087:
088: if (plist == null) {
089: System.out.println("-");
090: } else {
091: for (int i = 0; i < plist.size(); i++) {
092: System.out.println(i + " " + plist.get(i));
093: }
094: }
095:
096: if (parray == null) {
097: System.out.println("-");
098: } else {
099: 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: servletResponse.getWriter().print("Direct stream output...");
111: return null;
112: }
113:
114: // ---------------------------------------------------------------- 4
115:
116: /**
117: * Forward.
118: */
119: public String fff() {
120: System.out.println(">HelloAction.fff");
121: return "forward:/hello.again.html";
122: }
123: }
|