If I use a slightly modified showcase example (Forms.DataType Reuse) and show two textboxes instead of one with the zip-Code, the above warning is displayed.
This happens not only if you do 'zipCodeField.setType(new ZipCodeUSType())' twice, but also if you use a variable and use that variable twice. Ex. 'zipCodeField.setType(myZipCodeUSType)'.
The only way IMHO to avoid this kind of warning, is to use instantiate new SimpleType-Subclasses with different names, which is somehow against the reuse pattern.
Are there better ways on defining new datatypes on datasources, or is this just a bug?
This happens not only if you do 'zipCodeField.setType(new ZipCodeUSType())' twice, but also if you use a variable and use that variable twice. Ex. 'zipCodeField.setType(myZipCodeUSType)'.
The only way IMHO to avoid this kind of warning, is to use instantiate new SimpleType-Subclasses with different names, which is somehow against the reuse pattern.
Are there better ways on defining new datatypes on datasources, or is this just a bug?
Code:
public void onModuleLoad() {
DataSource dataSource = new DataSource();
ZipCodeUSType zipCodeUSType = new ZipCodeUSType();
DataSourceField zipCodeField = new DataSourceField();
zipCodeField.setName("zipCode");
zipCodeField.setTitle("Zip Code");
//zipCodeField.setType(new ZipCodeCustomType("nameType1"));
zipCodeField.setType(zipCodeUSType);
DataSourceField zipCodeField2 = new DataSourceField();
zipCodeField2.setName("zipCode2");
zipCodeField2.setTitle("Zip Code2");
//zipCodeField.setType(new ZipCodeCustomType("nameType2"));
zipCodeField2.setType(zipCodeUSType);
dataSource.setFields(zipCodeField, zipCodeField2);
final DynamicForm boundForm = new DynamicForm();
boundForm.setWidth(300);
boundForm.setDataSource(dataSource);
IButton button = new IButton("Validate");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
boundForm.validate();
}
});
VLayout layout = new VLayout(10);
layout.setMembers(boundForm, button);
layout.draw();
}
public static class ZipCodeUSType extends SimpleType {
public ZipCodeUSType() {
super("zipCodeUS", FieldType.TEXT);
RegExpValidator validator = new RegExpValidator("^\\d{5}(-\\d{4})?$");
setValidators(validator);
}
}
public static class ZipCodeCustomType extends SimpleType {
public ZipCodeCustomType(String name) {
super(name, FieldType.TEXT);
RegExpValidator validator = new RegExpValidator("^\\d{5}(-\\d{4})?$");
setValidators(validator);
}
}
Comment