自动从实体类@Size值复制inputText maxlength [英] Automatically copy inputText maxlength from entity class @Size value

查看:254
本文介绍了自动从实体类@Size值复制inputText maxlength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将<h:inputText>标签的maxlength属性设置为其实体类@Size最大值相同?

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

例如,给定:

@Size(max = 50)
String name;

...以某种方式自动/以编程方式将数字50设置为:

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

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

推荐答案

这可以使用 Apache MyFaces完成扩展程序验证程序,ExtVal.

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

此链接此链接说明如何将ExtVal添加到您的项目中.您需要添加所需的jar并在字段上方添加注释@MaxLength,然后您会在html输入中看到maxLength.

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.

这篇关于自动从实体类@Size值复制inputText maxlength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆