New datatape


I would like to create a new datatype, which is basically a string and automatically converts all the contents into uppercase.

What would be the best solution for that. Do I need to create and implement it through datatypes.xml?

A sample would be highly appreciated.


Hi Darius,

You can find a few samples here:

1 Like

Hi Konstantin.
Thank you for the prompt reply.
I created a new datatype class and also added an entry to metadata.xml, but my new datatype still does not appear in Studio. What might be a problem? Thanks

import com.haulmont.chile.core.datatypes.impl.StringDatatype;
import javax.annotation.Nonnull;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.text.ParseException;
import java.util.Locale;
public class CodeDatatype extends StringDatatype {
public static final String NAME = "code";
public Class getJavaClass() {
return String.class;
public String getName() {
return NAME;
public int getSqlType() {
return Types.VARCHAR;
public String format(Object value) {
return (value == null ? "" : (String) value).toUpperCase();
public String format(Object value, Locale locale) {
return (value == null ? "" : (String) value).toUpperCase(locale);
public String parse(String value) {
return value.toUpperCase();
public String parse(String value, Locale locale) throws ParseException {
return value.toUpperCase(locale);
public String read(ResultSet resultSet, int index) throws SQLException {
return resultSet.getString(index).toUpperCase();
public void write(PreparedStatement statement, int index, Object value) throws SQLException {
if (value == null) {
statement.setString(index, null);
} else {
String s = (String) value;
statement.setString(index, s.toUpperCase());

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<metadata xmlns="[url=]">[/url];
<datatype class="" javaType="java.lang.String"></datatype>
<metadata-model root-package="" namespace="sample"/>

Are you sure it doesn’t appear? It can be on the next page of the drop-down list, have you scrolled to the end?

1 Like

Ups. You are right. It is indeed on the next page. Learning new things every day. Thanks

The only thing is, I do not see length attribute, and the DB scripts are created without the length.
Do I need to do this manually? Thanks



Hi Konstantin,

I would like to limit the length of the column. If I modify the entity java file, by adding length attribute to the column, and amending the table creation script, next time when I use cuba studio to add additional fields, these changes I did (i. e. length attribute) get overwritten by the studio.

Another thing I noticed is, if I use custom data types, Entity Inspector doesn’t work anymore. This is the case even in the sample application cuba-sample-datatype. If I open Entity Inspector in Administration menu and try to create a new record I get the following error message

If I need these custom data type columns in almost all of my entities. If I do that I will loose the very convenient way to quickly insppect and amend records through entity inspector.

Could you please suggest, what would be the best way to deal that? Should I use some different approach to create a column which converts and displays it’s contents in uppercase?

Thank you very much.

Hi Darius,

In order to tell Studio what column type to generate, add sqlType=“varchar(50)” attribute to your type registration in metadata.xml as is done here for PhoneDatatype.

As for Entity Inspector error on custom datatypes, it is definitely a bug and we’ll fix it in one of the next bug-fix releases.

Also, have you seen this improvement that was done in response to your request about automatic converting to upper case?

Hi Konstantin.

I saw that it is possible to define teh field length through sqlTYpe attribute. And this is fine for the special type of field like phone. But wouldn’t it be better to have ability to set the length of the field for the data type derived from StringDatatype. Maybe sometimes in the future version.

I 've never seen that improvement, and I am very impressed, that Cuba team did that. I was not using the studio and platform for some time, thats probably why I missed that. Many thanks for that :slight_smile:

Could I suggest one more improvement? It would be nice if we can define this option not on UI, but on entity level. Then it would work even in Entity Inspector and we would never need to worry about UI, for it would propagate to UI also.


I’ve created two issues:

STUDIO-3720 Optional arbitrary column definition for entity attribute - it will enable defining custom column parameters for any attribute

PL-9149 Annotation on entity attribute to convert string values to upper case - it will be a nice feature

Thank you for your feedback!

1 Like

:ticket: See the following issue in our bug tracker: