I "completed" the first form to submit "new data".
Actually it is the "register form" to register as a new User. I did not (yet) concentrate on the whole "confirm your registration in the email" stuff.
My main focus was on validation of the entered data through the REST call against the server. And I wanted to be able to create error messages for every HTML input field, every one with a seperate message. And every message also localized in every available language.
The result looks like this:
Go to
http://test.client.oregami.org/#/register
There you can see the HTML form. I do not use client side validation, everything is validated on the server.
So enter some values and press "submit". Ths creates a REST call against
http://test.server.oregami.org/user (POST) with this JSON data:
Code: Select all{
"username":"test",
"email":"test@kultpower.de",
"password":"12345"
}
The server walks through the java code (UserResource.createUser => UserServiceImpl.registerUser => UserValidator.validateForRegister => UserValidator.validateRequiredFields) and creates a (potentially filled) List<ServiceError> packed in a ServiceResult<User>. If the List<ServiceError> contains at least one error, an HTTP status code 409 "Conflict" is returned. The body of that HTTP error contains the error list as JSON again:
Code: Select all[
{
"messageName":"USER_USERNAME_TOO_SHORT",
"context":{
"field":"user.username"
}
},
{
"messageName":"USER_PASSWORD_TOO_SHORT",
"context":{
"field":"user.password"
}
}
]
These error values are automatically processed by the JavaScript client. The error messages are assigned the the proper input field and translated to the localized message via AngularJS
language files for
angular-translate. And the input fields with errors are then marked with red colors.
"It's that simple, isn't that great?" (who said this?)
PS: Yes I know that if you call (HTTP GET)
http://test.server.oregami.org/user the list exposes the (hashed) password values which is not very nice. This will change of course in the future.