Required vs RequiredString or how loosing 1 hour

Struts 2 has two type of required validator.

  • required: checks that the value is not null
  • requiredstring: checks that the value is a string and that the string is not empty.

It is important to note the differences between those 2 validators.

For example, when using textbox linked to String attribute, Struts creates empty string. If the required validator is used to check the form values, the form will be validated because the text will not be null.

With the requiredstring validator, the form will not be validated.

As a conclusion, I strongly recommend not to use required validator for String field.

Comments are closed.