@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");
   }
 }
Exemple #2
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();
  }