Predefined values to select in cuba?

Hi community,

I want to ask:
if a user open the editor-view for an entity and try to set for example a value,
is there a way, how I can implement, or define, that only values from (1-10) can be selected?

Thank you

Hi,

Maybe, the Bean Validation mechanism is what you need?

@Min(1) // minimum value
@Max(10) // maximum value
@Column(name = "GRADE", nullable = false)
protected Integer grade;
1 Like

Thanks,

that will solve it I think :slight_smile:

Does I need to change something in mysql-script for it?
Or is it enough to put @Min and @max to entity class?

Thanks

Bean validation doesn’t affect the database anyhow. It is implemented only on the middleware. So, the annotations for the entity fields will be enough.

1 Like

@shiryaeva, would a regular expression be easier to implement than a Bean Validation since this can be placed on the entity creation point?

If you just want to limit the number of characters matched by an expression, most regular expressions support bounds by using braces. For instance,

\d{3}-\d{3}-\d{4}
will match (US) phone numbers: exactly three digits, then a hyphen, then exactly three digits, then another hyphen, then exactly four digits.

Likewise, you can set upper or lower limits:

\d{5,10}
means “at least 5, but not more than 10 digits”.

What do you think?

Regards,
Kenince

Hi,

We didn’t invent anything new in the Bean Validation mechanism. We just provided the way to use JSR-*** standards and Hibernate Validator as the implementation. Which way to use, it’s up to you.