All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.data.validation.Error Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package play.data.validation;

import play.i18n.Messages;

/**
 * A validation error.
 */
public class Error {

    String message;
    String key;
    String[] variables;

    public Error(String key, String message, String[] variables) {
        this.message = message;
        this.key = key;
        this.variables = variables;
    }
    
    /**
     * @return The translated message
     */
    public String message() {
        return message(key);
    }
    
    /**
     * @return The field name
     */
    public String getKey() {
        return key;
    }
    
    /**
     * @param key Alternate field name (default to java variable name)
     * @return The translated message
     */
    public String message(String key) {
        key = Messages.get(key);
        Object[] args = new Object[variables.length + 1];
        System.arraycopy(variables, 0, args, 1, variables.length);
        args[0] = key;
        return Messages.get(message, args);
    }

    @Override
    public String toString() {
        return message();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy