From the course: Java EE: Bean Validation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Numerical constraints implementation

Numerical constraints implementation

From the course: Java EE: Bean Validation

Start my 1-month free trial

Numerical constraints implementation

- [Instructor] Okay so now I'm going to open the transaction class, which we can open from the model package. This class represents a transaction in the stock, which might be either a buy or a sell instruction. And as you can see, it has the quantity filled which holds the number of stocks to be traded. Logically, this must be a positive value. So what I'm going to do is I'm going to use the positive bean validation constraint on this field. So here I'm just going to add our positive constraint, at positive. Further down, you can see that there is a price limit field, which is the maximum or minimum price the client wishes to trade stock. Now this field must be more than zero. So here I have a choice of which constraint to use. I can use the Min constraint and parse at the value zero. However, this constraint says that the value must be either zero or more. But I think that this constraint is a little bit too coarse-grained for my needs. I want to ensure that the price is not zero but…

Contents