示例#1
0
 public List<ValidationError> errors(String fieldName) {
   ExecutionContext ec = ExecutionContext.currentContext();
   ActionBeanContext abc = ec.getActionBeanContext();
   List<ValidationError> res = null;
   if (abc != null) {
     ValidationErrors errors = abc.getValidationErrors();
     if (errors != null) {
       res = errors.get(fieldName);
     }
   }
   return res == null ? Collections.emptyList() : res;
 }
  /**
   * calling injectors post creation on Action beans and Interceptors
   *
   * @param context
   * @return
   * @throws Exception
   */
  public Resolution intercept(ExecutionContext context) throws Exception {
    Configuration conf = StripesFilter.getConfiguration();

    FilterConfig filterConfig = conf.getBootstrapPropertyResolver().getFilterConfig();
    String className = filterConfig.getInitParameter(INJECTOR_FACTORY_CLASS);
    String methodName = filterConfig.getInitParameter(INJECTOR_FACTORY_METHOD);

    Injector injector = null;
    try {
      Class clazz = Class.forName(className);
      Method method = clazz.getMethod(methodName);
      injector = (Injector) method.invoke(null);
    } catch (ClassNotFoundException e) {
      log.error("Injector factory class not found - " + className, e);
      throw new Exception("Injector factory class not found - " + methodName, e);
    } catch (NoSuchMethodException e) {
      log.error("Injector factory method not found - " + methodName + " in class " + className, e);
      throw new Exception(
          "Injector factory method not found - " + methodName + " in class " + className, e);
    } catch (SecurityException e) {
      log.error(
          "SecurityException when trying to invoke - " + methodName + " in class " + className, e);
      throw new Exception(
          "SecurityException when trying to invoke - " + methodName + " in class " + className, e);
    } catch (IllegalAccessException e) {
      log.error(
          "IllegalAccessException when trying to invoke - " + methodName + " in class " + className,
          e);
      throw new Exception(
          "IllegalAccessException when trying to invoke - " + methodName + " in class " + className,
          e);
    } catch (IllegalArgumentException e) {
      log.error(
          "IllegalArgumentException when trying to invoke - "
              + methodName
              + " in class "
              + className,
          e);
      throw new Exception(
          "IllegalArgumentException when trying to invoke - "
              + methodName
              + " in class "
              + className,
          e);
    } catch (InvocationTargetException e) {
      log.error(
          "InvocationTargetException when trying to invoke - "
              + methodName
              + " in class "
              + className,
          e);
      throw new Exception(
          "InvocationTargetException when trying to invoke - "
              + methodName
              + " in class "
              + className,
          e);
    }

    //    if (context.getActionBean() != null) injector.injectMembers(context.getActionBean());
    if (context.getActionBeanContext() != null)
      injector.injectMembers(context.getActionBeanContext());

    for (Interceptor interceptor : conf.getInterceptors(context.getLifecycleStage())) {
      if (interceptor != null) injector.injectMembers(interceptor);
    }

    return context.proceed();
  }