[英]Automatically set h:inputText maxlength based on Bean Validation @Size
I use JSF 2 and Hibernate Validator 5.1 in a web application. 我在Web应用程序中使用JSF 2和Hibernate Validator 5.1。
I use the annotations like @Size
or @NotNull
in my beans to validate automatically my HTML forms. 我在
@NotNull
中使用@Size
或@NotNull
类的注释来自动验证HTML表单。
It works perfectly but I would like to know if there is a way to automatically limit the number of characters typed in an input text (ie set the attribute maxlength in HTML) based on the @Size
annotation. 它可以完美工作,但是我想知道是否有一种方法可以基于
@Size
注释自动限制输入文本中键入的字符数(即,在HTML中设置属性maxlength)。
HTML5 + JSF 2.2+ HTML5 + JSF 2.2+
If you're using HTML5 and JSF 2.2+, specify it as a passthrough attribute . 如果您使用的是HTML5和JSF 2.2+,则将其指定为passthrough属性 。
<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
<h:inputTextarea value="#{bean.text}" a:maxlength="2000" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.