Search in sources :

Example 1 with Form

use of org.apache.commons.validator.Form in project sonarqube by SonarSource.

the class JavascriptValidatorTag method renderJavascript.

/**
     * Returns fully rendered JavaScript.
     *
     * @since Struts 1.2
     */
protected String renderJavascript() throws JspException {
    StringBuffer results = new StringBuffer();
    ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
    ValidatorResources resources = (ValidatorResources) pageContext.getAttribute(ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), PageContext.APPLICATION_SCOPE);
    if (resources == null) {
        throw new JspException("ValidatorResources not found in application scope under key \"" + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
    }
    Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);
    Form form = null;
    if ("true".equalsIgnoreCase(dynamicJavascript)) {
        form = resources.getForm(locale, formName);
        if (form == null) {
            throw new JspException("No form found under '" + formName + "' in locale '" + locale + "'.  A form must be defined in the " + "Commons Validator configuration when " + "dynamicJavascript=\"true\" is set.");
        }
    }
    if (form != null) {
        if ("true".equalsIgnoreCase(dynamicJavascript)) {
            results.append(this.createDynamicJavascript(config, resources, locale, form));
        } else if ("true".equalsIgnoreCase(staticJavascript)) {
            results.append(this.renderStartElement());
            if ("true".equalsIgnoreCase(htmlComment)) {
                results.append(HTML_BEGIN_COMMENT);
            }
        }
    }
    if ("true".equalsIgnoreCase(staticJavascript)) {
        results.append(getJavascriptStaticMethods(resources));
    }
    if ((form != null) && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) {
        results.append(getJavascriptEnd());
    }
    return results.toString();
}
Also used : Locale(java.util.Locale) JspException(javax.servlet.jsp.JspException) Form(org.apache.commons.validator.Form) ValidatorResources(org.apache.commons.validator.ValidatorResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Aggregations

Locale (java.util.Locale)1 JspException (javax.servlet.jsp.JspException)1 Form (org.apache.commons.validator.Form)1 ValidatorResources (org.apache.commons.validator.ValidatorResources)1 ModuleConfig (org.apache.struts.config.ModuleConfig)1