Automatically copy inputText maxlength from entity class @Size value

不问归期 提交于 2019-12-23 16:01:42

问题


Is it possible to set the maxlength attribute of an <h:inputText> tag to be the same as its entity class @Size max value?

For example, given:

@Size(max = 50)
String name;

...somehow automatically/programmatically set the number 50 in:

<h:inputText id="name" maxlength="50" .../>

回答1:


This can be done using Apache MyFaces Extensions Validator, ExtVal.

This link and this link explain how to add ExtVal into your project. You need to add the required jars and to add the annotation @MaxLength above the field, and you will see the maxLength inside the html input.



来源:https://stackoverflow.com/questions/8575770/automatically-copy-inputtext-maxlength-from-entity-class-size-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!