Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.sourceforge.jsdialect.validation;
 
Client-side validation using jQuery-Validation plugin for a JSR-303 annotated Java class. Could use th:object and th:field attribute values, like:
 <form th:object="${product" th:validate="${product}">
         <input type="text" th:field="*{description}" />
    </form>
 }
 
Also could use defined values, as in:
 <form th:validate="${product">
         <input type="text" name="description" />
    </form>
 }
 
A second parameter could be provided to prevent mandatory asterisks HTML generation:
 <form th:validate="${product, false">
         <input type="text" name="description" />
    </form>
 }
 
public class ValidateAttrProcessor extends AbstractAttrProcessor {

    
jQuery-validation-plugin 1.8.1 supported locales.
    private final static String[] jqueryValidationLanguages = {"ar""bg""ca""cn""cs""da""de""el",
        "es""fa""fi""fr""ge""he""hu""it""ja""kk""lt""lv""nl""no""pl""ro""ru",
        "se""si""sk""sr""th""tr""tw""ua""vi""de""nl""pt"};
    private JsDialect dialect;
    public ValidateAttrProcessor(JsDialect dialect) {
        super("validate");
        this. = dialect;
    }
    @Override
    public int getPrecedence() {
        return 10000;
    }
    @Override
    public ProcessorResult processAttribute(Arguments argumentsElement elementString attributeName) {
        // Add jquery scripts
        addScripts(arguments);
        new ValidateCommand(argumentselementattributeName).execute();
        return .;
    }

    
Adds jQuery dependencies. If jQuery-validation-plugin support user language, adds localization script.
    private void addScripts(Arguments arguments) {
        .addScript(arguments.);
        String language = arguments.getContext().getLocale().getLanguage();
        if (ArrayUtils.contains(language)) {
            .addScriptAfter(arguments."messages_" + language + ".js");
        }
    }
New to GrepCode? Check out our FAQ X