Now, to mark the bad inputs, we need to ask ourselves a couple of questions. Well, it’s all about the experience you want to provide. For the purpose of this post, I’m going to do with the simplest one — marking red the bad inputs, without anything else.
We can then evaluate a particular condition on every value change, and do something based on it. We used a simple expression to compute whether the button should be disabled (aka when either of email or password was empty): It got the job done.
If the conversion was successful, the method returns the result in the correct type.
If the conversion failed, the code outputs and error message and requests the user to re-enter a proper input.
You’ll build a simple Spring MVC application that take user input and checks the input using standard validation annotations.
As a rule of thumb, you should never trust the data received from end users and should always validate it before putting it to good use.
expects an integer, next Double expects a double, next Float expects a float and next Line expects a string.
With the exception of strings, if a user inputs the wrong type, the code will produce an exception and (if not handled correctly) will stop.
Whenever a user is asked to provide input, the program should expect errors.