Пример #1
0
  protected void handleError(Controller controller) {

    controller.setAttr("status", "error");
    String actionKey = getActionKey();
    System.out.println("actionKey: " + actionKey);
    controller.renderJson();
  }
Пример #2
0
 @Override
 protected void handleError(Controller c) {
   c.keepModel(User.class);
   c.keepPara();
   c.setAttr("state", "failure");
   if (ReturnKit.isJson(c.getRequest())) c.renderJson();
   else {
     if (getActionKey().equals("/member/control")) c.forwardAction("/member");
   }
 }
  @Override
  public void intercept(ActionInvocation ai) {
    ai.invoke();

    Controller c = ai.getController();
    HttpSession hs = c.getSession(false);
    if (hs != null) {
      c.setAttr("session", new HttpSessionHashModel(hs, ObjectWrapper.DEFAULT_WRAPPER));
    }
  }
Пример #4
0
  /**
   * add edit 无需处理
   *
   * <p>GET /user ---> index GET /user/id ---> show POST /user ---> save PUT /user/id ---> update
   * DELECT /user/id ---> delete
   */
  public void intercept(ActionInvocation ai) {
    // 阻止 JFinal 原有规则 action 请求
    Controller controller = ai.getController();
    Boolean isRestfulForward = controller.getAttr(isRestfulForwardKey);
    String methodName = ai.getMethodName();
    if (set.contains(methodName) && isRestfulForward == null) {
      ai.getController().renderError(404);
      return;
    }

    if (isRestfulForward != null && isRestfulForward) {
      ai.invoke();
      return;
    }

    String controllerKey = ai.getControllerKey();
    String method = controller.getRequest().getMethod().toUpperCase();
    String urlPara = controller.getPara();
    if ("GET".equals(method)) {
      if (urlPara != null && !"edit".equals(methodName)) {
        controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
        controller.forwardAction(controllerKey + "/show/" + urlPara);
        return;
      }
    } else if ("POST".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/save");
      return;
    } else if ("PUT".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/update/" + urlPara);
      return;
    } else if ("DELETE".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/delete/" + urlPara);
      return;
    }

    ai.invoke();
  }
Пример #5
0
  /**
   * 该拦截器取得当前ActionPath,从Cache中检查是否有传送给当前Action的Flash对象Map 若有,则遍历Map,并将所有key,value注入到当前的request请求中。
   */
  public void intercept(ActionInvocation ai) {
    Controller c = ai.getController();
    HttpSession session = c.getSession(false);
    if (null == session) {
      return;
    }

    // String curAction = ai.getViewPath()+ai.getMethodName();
    String curAction = c.getRequest().getServletPath();
    ConcurrentHashMap<String, Object> flashMap = c.getFlashManager().getFlash(session, curAction);
    if (flashMap != null) {
      for (Entry<String, Object> flashEntry : flashMap.entrySet()) {
        c.setAttr(flashEntry.getKey(), flashEntry.getValue());
      }
    }
    ai.invoke();
  }
  @Override
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    int id = controller.getParaToInt("id", 0);
    if (id == 0) {
      controller.renderJson("msg", "id is blank");
      return;
    }

    User targetUser = UserService.getById(id);
    if (targetUser == null) {
      controller.renderJson("msg", "no such user");
      return;
    }

    controller.setAttr("targetUser", targetUser);

    ai.invoke();
  }