Page History
...
This is an example of validating the size of a column of type TEXT or MEDIA. The validation rule is that the size must be lower or equal to the value given by the developer by setting the length property in the Validation tab.
Code Block | ||
---|---|---|
| ||
public class SizeValidator implements IColumnValidator { private static final String LENGTH_PROPERTY = "length"; public Map getDefaultProperties() { Map props = new HashMap(); props.put(LENGTH_PROPERTY, ""); return props; } public String getName() { return "servoy.SizeValidator"; } public int[] getSupportedColumnTypes() { return new int[] { IColumnTypes.TEXT, IColumnTypes.MEDIA }; } public void validate(Map props, Object arg) throws IllegalArgumentException { String propLength = (String)props.get(LENGTH_PROPERTY); int length = new Double(propLength.replace(',', '.')).intValue(); if (arg instanceof byte[] && ((byte[])arg).length > length) { throw new IllegalArgumentException(); } else if (arg instanceof String && ((String)arg).length() > length) { throw new IllegalArgumentException(); } } } |
Overview
Content Tools
Activity