Validating user input
With the use of the web framework, the application implicitly checks that the form fields for the topic and content text are present. The check happens at the time the framework populates the FormData
struct with the values of the form fields. There is no way to display this error yet. If you remove one of the form fields and run the application, then the application seems to crash. As the same approach is used to validate user input, we need to fix this.
Displaying error messages with @errorDisplay
If an error occurs, then a web page must be rendered to show the error message. You use the @errorDisplay
annotation to define the function to be called in order to display the error:
@errorDisplay!getError void createNewNote(FormData form) { /* ... */ }
The getError()
method takes a _error
parameter, which receives information about the error. In the simplest cases, the type of the parameter is string
and contains an error message. Note the underscore in the parameter name...