官术网_书友最值得收藏!

How it works...

Let's check each declared constraint:

    @NotBlank (message = "Name should not be blank")
@Size (min = 4, max = 10,message = "Name should be between
4 and 10 characters")
private String name;

The @NotBlank annotation will deny not only null values, but also whitespace values, and @Size speaks for itself:

    @Email (message = "Invalid e-mail format")
@NotBlank (message = "E-mail shoud not be blank")
private String email;

The @Email constraint will check the email string format:

    @PastOrPresent (message = "Created date should be past or present")
@NotNull (message = "Create date should not be null")
private LocalDate created;

@PastOrPresent will constrain LocalDate to be in the past or until the present date. It can't be in the future.

Here, we can't use @NotBlank as there is no blank date, only null, so we avoid this by using @NotNull:

    @Future (message = "Expires should be a future date")
@NotNull (message = "Expires should not be null")
private LocalDate expires;

This is the same as the preceding constraint, but constraints for a future date.

In our UI, there are two places we should take a careful look at:

 <h:inputText id="created" value="#{user.created}">
<f:convertDateTime type="localDate" pattern="dd/MM/uuuu" />
</h:inputText>

...

<h:inputText id="expire" value="#{user.expires}">
<f:convertDateTime type="localDate" pattern="dd/MM/uuuu" />
</h:inputText>

Here, we are using convertDateTime to automatically convert the data that's inputted into inputText according to the dd/MM/uuuu pattern.

主站蜘蛛池模板: 平顺县| 东方市| 宝兴县| 广灵县| 哈密市| 囊谦县| 中江县| 北碚区| 桓台县| 图木舒克市| 临城县| 西乌珠穆沁旗| 昌平区| 奉新县| 那曲县| 宁晋县| 无锡市| 喜德县| 报价| 舞阳县| 乐都县| 吉林市| 成安县| 井冈山市| 松潘县| 江津市| 中阳县| 余江县| 东海县| 榆社县| 忻州市| 建昌县| 济阳县| 桦川县| 肇东市| 娱乐| 庆阳市| 西乡县| 柞水县| 长沙市| 岳西县|