ValidateNestedProperties field sorting

228 views Asked by At

Good day,

I have some mandatory field need to validate when running update() method. The validation is working fine. But I fail to sort the sequence.

My code is as follow:

@ValidateNestedProperties({
            @Validate(field = "currentPassword", on = { "update" }, required = true, mask = "^([^\\s]+)$"),
            @Validate(field = "newPassword", on = { "update" }, required = true, mask = "^([^\\s]+)$"),
            @Validate(field = "confirmPassword", on = { "update" }, required = true, mask = "^([^\\s]+)$") })

And the screen in browser will show as follow:

- Confirm Password is a mandatory field
- Current Password is a mandatory field
- New Password is a mandatory field

I guess it display sort by ascending order, but actually I wish to display at my own ways, which is currentPassword, then newPassword, and then confirmPassword.

I tried google on this but I think my question is wrong thus I cant get the correct response.

Kindly advise.

1

There are 1 answers

0
Richard Osseweyer On

The easiest way to achieve that is to specify the error messages in the desired order in the output:

<stripes:errors field="currentPassword"/> 
<stripes:errors field="newPassword"/> 
<stripes:errors field="confirmPassword"/> 

If there may be additional errors not bound to a field show them like so:

<stripes:errors globalErrorsOnly="true"/>

Sorting is tricky since error messages are kept in a HashMap. I suppose you would have to write your own implementation.

See this great article on the Stripes site: https://stripesframework.atlassian.net/wiki/display/STRIPES/Display+Errors

And the docs: http://stripes.sourceforge.net/docs/current/taglib/index.html