Search code examples
validationplayframeworkplayframework-2.0unobtrusive-validationjquery-validation-engine

Client/server side validation with Play Framework


Being a .Net/MVC developer for the past 6 years, I have been spoiled with some of the out of the box features. I have used the .Net validation annotations along with jQuery validation on the client side. I have been spoiled by the mode validation annotations working for both client side and server side removing unnecessary redundancies.

I am now experimenting with Java and Play framework. I noticed that Play framework offers validation annotations as well but can only be verified on the server side. Is it possible to have a validation plugin (e.g. jQuery validation) to automatically take care of this validation by inheriting from the model annotations (similar to .Net)

Any advice or experience will be greatly appreciated


Solution

  • Shortly, no, it's not possible to inherit constraints from models.

    Edit: Just found it seconds ago: https://github.com/loicdescotte/Play2-HTML5Tags
    This is 3-rd party module which brings new set of form helpers which also inherits constraints from models (Java/Scala) awesome!

    Anyway this description is still valid:
    Play's developers tries do not influence it by third party libraries - even such as jQuery, fortunately you can for an example disable Play's constraints and errors and then handle your form on the client side with jQuery Validation Plugin as normal form.

    See '_help -> "Custom help", '_showConstraints -> false and
    '_showErrors -> false in the docs