I would like to suggest an API improvement in the fluent interface, which 
should not break backwards compatibility. Currently if you create, say, a 
mandatory FileUploadField, you cannot do this.

/FileUploadField lFileUploadField = new FileUploadField("fileInput", 
...).setRequired(true);
/
Because setRequired is actually implemented in FormComponent and returns a 
FormComponent. By adding the component type to the generics of FormComponent 
and casting the return value, this could be resolved.

/public abstract class FormComponent<T, C>/
/{
    public C setRequired(boolean required)
    {
        ...
        return (C)this;
    }
}
/
/public class FileUploadField extends FormComponent<List<FileUpload>, 
FileUploadField>/
/{
    ...
}

/Now the setRequired method in FormComponent knows exactly what type to return. 
The casting naturally does not earn a style award, but the improvement in the 
API does, and in my opinion is worth the trade-off.

Tom

Reply via email to