How do I enforce the order which error messages are displayed when using validation annotations?

David Spence

I have the below model, view and error messages.

Model

public class LoginModel {
    @Required(message = "validation.required.email")
    public String email;

    @Required(message = "validation.required.password")
    public String password;
}

View

@for((field, validationErrors) <- myForm.errors) {
    @for(validationError <- validationErrors) {
        <li>@Messages(validationError.message)</li>
    }
}

conf/messages

error.no_email=You must enter an email
error.no_password=You must enter a password

The message "You must enter a password" appears before the "You must enter an email". I would like them in the same order I have them on my form (which is email followed by password). Is there a way to define the order which error messages are displayed when errors are added automatically by play from validation annotations?

David Spence

It's a bit of an overheard (and I don't like the solution) but it's possible via:

@for(error <- form("email").errors) {
    <li>@Messages(error.message)</li>
}

@for(error <- form("password").errors) {
    <li>@Messages(error.message)</li>
}

It still means that the order of the messages are not guaranteed for each field, but at least you can enforce the order at a field level so they can match up to the order of the fields on your form.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I combine resource strings for validation attribute error messages?

From Dev

how to configure messages property for validation using annotations spring

From Dev

how do I fix the menu items displayed when using OpenOffice?

From Dev

how do I fix the menu items displayed when using OpenOffice?

From Dev

Spring MVC validation annotations not displaying error messages

From Dev

Spring MVC validation annotations not displaying error messages

From Dev

How do I deal with these error messages in Processing using the UnfoldingMaps library

From Dev

How do I resolve this "Access is denied" error which occurs when using xp_cmdshell in Microsoft SQL?

From Dev

How can I get validation messages to render on collection properties when using new guid indexes each time?

From Dev

How do I enforce settings for an extension in chrome using mac?

From Dev

When I find the max value in an array how do I find out which order it was in?

From Dev

How to hold entered values in input fields when server side validation messages are displayed at correspoing fields in jsp

From Dev

How to push only validation error messages into an array using Laravel

From Dev

in C++, how should I enforce the order of composited object constructors in an initializer list when they have dependencies

From Dev

How do I find which messages an object understands?

From Dev

How do I find which messages an object understands?

From Dev

Validation messages are not getting displayed when trancluding a directive within another directive

From Dev

Validation messages are not getting displayed when trancluding a directive within another directive

From Dev

Some error messages displayed when I start terminal (both as root and as normal user)

From Dev

Some error messages displayed when I start terminal (both as root and as normal user)

From Dev

How can I get English error messages when loading XML using MSXML

From Dev

How do I account for messages being broken up when using sockets?

From Dev

How can I test validation annotations?

From Dev

How do I enforce an auto increment in postgres?

From Dev

How do I enforce a password complexity policy?

From Dev

How do I enforce a password complexity policy?

From Dev

How do I remove link annotations from a PDF using iText?

From Dev

How do I return multiple values using annotations?

From Dev

How do I map a List of Maps in Hibernate using annotations?

Related Related

  1. 1

    How do I combine resource strings for validation attribute error messages?

  2. 2

    how to configure messages property for validation using annotations spring

  3. 3

    how do I fix the menu items displayed when using OpenOffice?

  4. 4

    how do I fix the menu items displayed when using OpenOffice?

  5. 5

    Spring MVC validation annotations not displaying error messages

  6. 6

    Spring MVC validation annotations not displaying error messages

  7. 7

    How do I deal with these error messages in Processing using the UnfoldingMaps library

  8. 8

    How do I resolve this "Access is denied" error which occurs when using xp_cmdshell in Microsoft SQL?

  9. 9

    How can I get validation messages to render on collection properties when using new guid indexes each time?

  10. 10

    How do I enforce settings for an extension in chrome using mac?

  11. 11

    When I find the max value in an array how do I find out which order it was in?

  12. 12

    How to hold entered values in input fields when server side validation messages are displayed at correspoing fields in jsp

  13. 13

    How to push only validation error messages into an array using Laravel

  14. 14

    in C++, how should I enforce the order of composited object constructors in an initializer list when they have dependencies

  15. 15

    How do I find which messages an object understands?

  16. 16

    How do I find which messages an object understands?

  17. 17

    Validation messages are not getting displayed when trancluding a directive within another directive

  18. 18

    Validation messages are not getting displayed when trancluding a directive within another directive

  19. 19

    Some error messages displayed when I start terminal (both as root and as normal user)

  20. 20

    Some error messages displayed when I start terminal (both as root and as normal user)

  21. 21

    How can I get English error messages when loading XML using MSXML

  22. 22

    How do I account for messages being broken up when using sockets?

  23. 23

    How can I test validation annotations?

  24. 24

    How do I enforce an auto increment in postgres?

  25. 25

    How do I enforce a password complexity policy?

  26. 26

    How do I enforce a password complexity policy?

  27. 27

    How do I remove link annotations from a PDF using iText?

  28. 28

    How do I return multiple values using annotations?

  29. 29

    How do I map a List of Maps in Hibernate using annotations?

HotTag

Archive