書名: Jakarta EE Cookbook作者名: Elder Moraes本章字?jǐn)?shù): 209字更新時(shí)間: 2021-06-24 16:12:44
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.
推薦閱讀
- Mastering Visual Studio 2017
- C# 2012程序設(shè)計(jì)實(shí)踐教程 (清華電腦學(xué)堂)
- Microsoft Dynamics 365 Extensions Cookbook
- Network Automation Cookbook
- jQuery從入門到精通 (軟件開發(fā)視頻大講堂)
- Mastering Rust
- Android系統(tǒng)級(jí)深入開發(fā)
- Cocos2d-x Game Development Blueprints
- Laravel Application Development Blueprints
- OpenCV 3計(jì)算機(jī)視覺:Python語(yǔ)言實(shí)現(xiàn)(原書第2版)
- Python青少年趣味編程
- SCRATCH編程課:我的游戲我做主
- 絕密原型檔案:看看專業(yè)產(chǎn)品經(jīng)理的原型是什么樣
- JavaScript Security
- Unity3D游戲開發(fā)標(biāo)準(zhǔn)教程