Exemple #1
0
  /**
   * @param resources the validation resources
   * @return the static javascript methods
   */
  protected String getJavascriptStaticMethods(ValidatorResources resources) {
    StringBuffer sb = new StringBuffer("\n\n");

    Iterator actions = resources.getValidatorActions().values().iterator();
    while (actions.hasNext()) {
      ValidatorAction va = (ValidatorAction) actions.next();
      if (va != null) {
        String javascript = va.getJavascript();
        if (javascript != null && javascript.length() > 0) {
          sb.append(javascript + "\n");
        }
      }
    }
    return sb.toString();
  }
Exemple #2
0
  /**
   * Render both dynamic and static JavaScript to perform validations based on the supplied form
   * name.
   *
   * @param formName the key (form name)
   * @param getStatic indicates if the static methods should be rendered
   * @return the Javascript for the specified form
   * @throws Exception
   */
  protected String getJavascript(String formName, boolean getStatic) throws Exception {
    StringBuffer results = new StringBuffer();

    Locale locale = StrutsUtils.getLocale(request, session);

    Form form = resources.getForm(locale, formName);
    if (form != null) {
      results.append(getDynamicJavascript(resources, locale, form));
    }

    if (getStatic) {
      results.append(getJavascriptStaticMethods(resources));
    }

    if (form != null) {
      results.append(getJavascriptEnd());
    }

    return results.toString();
  }
Exemple #3
0
  /**
   * Get List of actions for the given Form.
   *
   * @param resources the validator resources
   * @param form the form for which the actions are requested
   * @return A sorted List of ValidatorAction objects.
   */
  protected List createActionList(ValidatorResources resources, Form form) {
    List actionMethods = new ArrayList();
    // Get List of actions for this Form
    for (Iterator i = form.getFields().iterator(); i.hasNext(); ) {
      Field field = (Field) i.next();
      for (Iterator x = field.getDependencyList().iterator(); x.hasNext(); ) {
        Object o = x.next();
        if (o != null && !actionMethods.contains(o)) {
          actionMethods.add(o);
        }
      }
    }

    List actions = new ArrayList();

    // Create list of ValidatorActions based on actionMethods
    for (Iterator i = actionMethods.iterator(); i.hasNext(); ) {
      String depends = (String) i.next();
      ValidatorAction va = resources.getValidatorAction(depends);

      // throw nicer NPE for easier debugging
      if (va == null) {
        throw new NullPointerException(
            "Depends string \"" + depends + "\" was not found in validator-rules.xml.");
      }

      String javascript = va.getJavascript();
      if (javascript != null && javascript.length() > 0) {
        actions.add(va);
      } else {
        i.remove();
      }
    }

    Collections.sort(actions, actionComparator);
    return actions;
  }