Package com.jfinal.core

Examples of com.jfinal.core.Controller


   * 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();
  }
View Full Code Here


/**
* Accept GET method only.
*/
public class GET implements Interceptor {
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    if ("GET".equalsIgnoreCase(controller.getRequest().getMethod()))
      ai.invoke();
    else
      controller.renderError(404);
  }
View Full Code Here

/**
* Accept POST method only.
*/
public class POST implements Interceptor {
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    if ("POST".equalsIgnoreCase(controller.getRequest().getMethod().toUpperCase()))
      ai.invoke();
    else
      controller.renderError(404);
  }
View Full Code Here

 
  @SuppressWarnings({"rawtypes", "unchecked"}) 
  public void intercept(ActionInvocation ai) {
    ai.invoke();
   
    Controller c = ai.getController();
    if (c.getRender() instanceof com.jfinal.render.JsonRender)
      return ;
   
    HttpSession hs = c.getSession(createSession);
    if (hs != null) {
      Map session = new JFinalSession(hs);
      for (Enumeration<String> names=hs.getAttributeNames(); names.hasMoreElements();) {
        String name = names.nextElement();
        session.put(name, hs.getAttribute(name));
      }
      c.setAttr("session", session);
    }
  }
View Full Code Here

public class IocInterceptor implements Interceptor {
 
  static ApplicationContext ctx;
 
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    Field[] fields = controller.getClass().getDeclaredFields();
    for (Field field : fields) {
      Object bean = null;
      if (field.isAnnotationPresent(Inject.BY_NAME.class))
        bean = ctx.getBean(field.getName());
      else if (field.isAnnotationPresent(Inject.BY_TYPE.class))
View Full Code Here

/**
* Force action no urlPara, otherwise render error 404 to client.
*/
public class NoUrlPara implements Interceptor {
  public void intercept(ActionInvocation invocation) {
    Controller controller = invocation.getController();
    if (controller.getPara() == null)
      invocation.invoke();
    else
      controller.renderError(404);
  }
View Full Code Here

    ReentrantLock previousLock = lockMap.putIfAbsent(key, lock);
    return previousLock == null ? lock : previousLock;
  }
 
  final public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    String cacheName = buildCacheName(ai, controller);
    String cacheKey = buildCacheKey(ai, controller);
    Map<String, Object> cacheData = CacheKit.get(cacheName, cacheKey);
    if (cacheData == null) {
      Lock lock = getLock(cacheName);
View Full Code Here

    }

    @Override
    public void intercept(ActionInvocation ai) {
        String actionKey = ai.getActionKey();
        Controller c = ai.getController();
        LogConfig log = acitonLogs.get(actionKey);
        if (log != null) {
            logFromConfig(c, log);
        }
        ai.invoke();
View Full Code Here

    private String localePara = "locale";
    private String skipFlagPara = "skipi18n";

    @Override
    public void intercept(ActionInvocation ai) {
        Controller controller = ai.getController();
        String language = controller.getAttr(languagePara);
        if (StrKit.isBlank(language)) {
            language = controller.getPara(languagePara, defaultLanguage);
        }
        String country = controller.getAttr(countryPara);
        if (StrKit.isBlank(country)) {
            country = controller.getPara(countryPara, defaultCountry);
        }
        Locale locale = new Locale(language, country);
        controller.setLocaleToCookie(locale);
        controller.setAttr(localePara, locale);
        ai.invoke();
        if (Boolean.TRUE.equals(ai.getController().getAttr(skipFlagPara))) {
            return;
        }
        Render render = controller.getRender();
        if (render == null) {
            render = RenderFactory.me().getDefaultRender(ai.getMethodName());
        }
        String view = render.getView();
View Full Code Here

    }

    @SuppressWarnings({ "rawtypes" })
    public void doIntercept(ActionInvocation ai) {
        config();
        Controller controller;
        controller = ai.getController();
        PageInfo pageInfo = PageInfoKit.injectPageInfo(model, controller,relations);
        extendsPageInfo(pageInfo);
        Page page = PageInfoKit.populate(pageInfo, this);
        controller.setAttr("pageInfo", pageInfo);
        controller.setAttr("page", page);
        ai.invoke();
    }
View Full Code Here

TOP

Related Classes of com.jfinal.core.Controller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.