Child pages
  • Providing Converters and Validators from Plugins

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

Note that IColumnConverter is considered to be deprecated, therefore in getColumnConverters() method do return an ITypedColumnConverter array.

The interface ITypedColumnConverter declares three methods that need to be implementedA converter class implementing the ITypedColumnConverter interface has to implement the following three methods:

  • convertFromObject()
    Converts from dataprovider value to db value

  • convertToObject()
    Converts from db value to dataprovider value

  • getToObjectType(one of TEXT, INTEGER, NUMBER, DATETIME or MEDIA)
    The dataprovider data type (so the resulting type of the convertToObject()).
    This type can be provided by using the IColumnTypes constants.

...

An IColumnValidator can also define properties in the getDefaultProperties() method, whose values will be set by the developer in UI, in the Validation tab.

...

Code Block
languagejava
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();
		}
	}
}