Abstract View Class & BeanValidationBinder

Hi, I’m creating an abstract view class like this:

public class BaseAppFormLayoutView<T> extends VerticalLayout implements View{ ... } The base abstract class provides the basic template for the table views such as basic format, access to datastore (using mongodb), save(), delete(), bind() methods, etc…
Everything works nice except whith BeanValidationBinder.

private Class<T> baseClass;
BeanValidationBinder<T> binder = new BeanValidationBinder<>(baseClass);

I get the following error

java.lang.NullPointerException: Bean type cannot be null.

I can do the binding in the class that inherits from BaseAppFormLayoutView, but it would be nice to have it in the abstract class.

Any thoughts ,workarounds?

Thanks,

Julio

Hi Julio,
what about having a protected constructor in BaseAppFormLayout that takes in input baseClass and instantiate the BeanValidationBinder? The subclasses will have a constructor that calls the super protected one with.

HTH
Marco

Yes I had solved it like this.

protected BeanValidationBinder<T> binder; ... and then instantiating the BeanValidationBinder once the form was associated to a Bean like this:

public void bind(T t){ this.t = t; if (t != null) binder = new BeanValidationBinder(t.getClass()); ... Thanks,

Julio