I am using a Form component to edit values in an Object . I have mapped an object using a LoadableDetachableModel to the form so that the value in the object is displayed on the form and updates are applied automatically.
final Form<Withdrawal> form = new Form<Withdrawal>("form",
new CompoundPropertyModel<Withdrawal>(ldm)) {
.... }
However, I have a problem with adding validators to form component such as StringValidator to text fields. I have a "comment" field ( one of the fields in the Withdrawal Object).
Ideally I want to add it as :
TextField<Withdrawal> tf_comments = new TextField<Withdrawal>("comment");
tf_comments.add( new StringValidator.MaximumLengthValidator(255));
form.add( tf_comments);
But since I cannot add StringValidators to it because StringValidator
for TextField<Withdrawal>
is not defined. So I am using the below and getting value of the field and setting it to object manually.
TextField<String> tf_comments = new TextField<String>("comment");
tf_comments.add( new StringValidator.MaximumLengthValidator(255));
form.add(tf_comments);
Is there a way to add a Validator directly on to TextField<Withdrawal>
?
Thank you.