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

Validation

Notice that each <h:inputField> tag has a nested <f:validateLength> tag. As its name implies, this tag validates that the entered value for the text field is between a minimum and maximum length. Minimum and maximum values are defined by the tag's minimum and maximum attributes. <f:validateLength> is one of the standard validators included with JSF. Just like with the required attribute of <h:inputText>, JSF will automatically display a default error message when a user attempts to submit a form with a value that does not validate:

Again, the default message and style can be overridden; we will cover how to do this later in the chapter.

In addition to <f:validateLength>, JSF includes other standard validators, which are listed in the following table:

Notice that in the description for <f:validateBean>, we briefly mentioned bean validation. The bean validation JSR aims to standardize JavaBean validation. JavaBeans are used across several other APIs that, up until recently, had to implement their own validation logic. JSF 2.0 adopted the bean validation standard to help validate named bean properties.

If we want to take advantage of bean validation, all we need to do is annotate the desired field with the appropriate bean validation annotation, without having to explicitly use a JSF validator.

For a complete list of bean validation annotations, refer to the javax.validation.constraints package in the Java EE 8 API at https://javaee.github.io/javaee-spec/javadocs/.

主站蜘蛛池模板: 宝坻区| 鹤峰县| 油尖旺区| 都江堰市| 全州县| 新民市| 如东县| 斗六市| 安义县| 互助| 民权县| 腾冲县| 唐海县| 囊谦县| 西丰县| 邛崃市| 景东| 涡阳县| 长武县| 宣化县| 福鼎市| 榕江县| 商南县| 林周县| 凤冈县| 贵南县| 深泽县| 苗栗县| 铁力市| 额尔古纳市| 贵定县| 新津县| 醴陵市| 宜章县| 蚌埠市| 大连市| 绥江县| 仙居县| 门源| 邵东县| 澎湖县|