Exemplo n.º 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();
  }
Exemplo n.º 2
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;
  }