| 1 |  |  package org.seasar.cubby.examples.guice.action; | 
  | 2 |  |   | 
  | 3 |  |  import org.seasar.cubby.action.ActionClass; | 
  | 4 |  |  import org.seasar.cubby.action.ActionContext; | 
  | 5 |  |  import org.seasar.cubby.action.ActionResult; | 
  | 6 |  |  import org.seasar.cubby.action.Forward; | 
  | 7 |  |  import org.seasar.cubby.action.Redirect; | 
  | 8 |  |  import org.seasar.cubby.action.RequestParameter; | 
  | 9 |  |  import org.seasar.cubby.action.Validation; | 
  | 10 |  |  import org.seasar.cubby.examples.guice.service.HelloService; | 
  | 11 |  |  import org.seasar.cubby.validator.DefaultValidationRules; | 
  | 12 |  |  import org.seasar.cubby.validator.ValidationRules; | 
  | 13 |  |  import org.seasar.cubby.validator.validators.RequiredValidator; | 
  | 14 |  |   | 
  | 15 |  |  import com.google.inject.Inject; | 
  | 16 |  |  import com.google.inject.servlet.RequestScoped; | 
  | 17 |  |   | 
  | 18 |  |  @RequestScoped | 
  | 19 |  |  @ActionClass | 
  | 20 | 3 |  public class HelloAction { | 
  | 21 |  |   | 
  | 22 | 3 |          ValidationRules validation = new DefaultValidationRules() { | 
  | 23 |  |                  @Override | 
  | 24 |  |                  public void initialize() { | 
  | 25 | 3 |                          add("name", new RequiredValidator()); | 
  | 26 | 3 |                  } | 
  | 27 |  |          }; | 
  | 28 |  |   | 
  | 29 |  |          @Inject | 
  | 30 |  |          private HelloService helloService; | 
  | 31 |  |   | 
  | 32 |  |          @Inject | 
  | 33 |  |          private ActionContext actionContext; | 
  | 34 |  |   | 
  | 35 |  |          @RequestParameter | 
  | 36 |  |          private String name; | 
  | 37 |  |   | 
  | 38 |  |          private String message; | 
  | 39 |  |   | 
  | 40 |  |          public String getName() { | 
  | 41 | 0 |                  return name; | 
  | 42 |  |          } | 
  | 43 |  |   | 
  | 44 |  |          public String getMessage() { | 
  | 45 | 0 |                  return message; | 
  | 46 |  |          } | 
  | 47 |  |   | 
  | 48 |  |          public ActionResult index() { | 
  | 49 | 1 |                  return new Forward("index.jsp"); | 
  | 50 |  |          } | 
  | 51 |  |   | 
  | 52 |  |          @Validation(rules = "validation", errorPage = "index.jsp") | 
  | 53 |  |          public ActionResult message() { | 
  | 54 | 1 |                  this.message = this.name + " " + helloService.getMessage(); | 
  | 55 | 1 |                  return new Forward("hello.jsp"); | 
  | 56 |  |          } | 
  | 57 |  |   | 
  | 58 |  |          public ActionResult back() { | 
  | 59 | 0 |                  actionContext.getFlashMap().put("notice", | 
  | 60 |  |                                  "Redirect OK!(this message is flash message)"); | 
  | 61 | 0 |                  return new Redirect(HelloAction.class); | 
  | 62 |  |          } | 
  | 63 |  |   | 
  | 64 |  |  } |