JSF h:inputTextarea 到 HTML textArea - 传递 maxlength 属性
我正在使用 Richfaces,并且尝试创建一个设置了 maxlength 属性的
<h:inputTextarea maxlength="100" cols="20" rows="10" value="#{bean.description}" id="description" />
I am using Richfaces and I am trying to make an <textArea>
with maxlength atrribute set but JSF seems not to pass the maxlength attribute from h:inputTextArea. Any ideas why this is happening?
<h:inputTextarea maxlength="100" cols="20" rows="10" value="#{bean.description}" id="description" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
h:inputTextarea
上不存在maxlength
(参见文档)。要添加验证器消息,请尝试
maxlength
doesn't exists onh:inputTextarea
(see doc).To add a validator message, try
我们的解决方案是在包含最大长度数字的文本区域前面放置一个额外的跨度。
你给这个类一个“display: none;”规则来隐藏它。然后,您使用 JavaScript 查找每个 span.maxlength 并将其中的数字移动到文本区域的 maxlength 属性中(使用 jQuery):
完成后,运行其他限制在文本区域中输入的 JavaScript。
哈基?是的。但是 JSF 不支持 maxlength 是很棘手的。
Our solution was to put an extra span immediately in front of the textarea that contained the maxlength number.
You give that class a "display: none;" rule to hide it. Then you use JavaScript to find each span.maxlength and move the number inside of it into the maxlength attribute of the textarea (using jQuery):
Once that's done, run your other JavaScript that limits typing in textareas.
Hacky? Yes. But JSF not supporting maxlength is hacky.
这实际上并不是 RichFaces 问题,而是与 JSF 相关。
之前也已经回答得比较好。请参阅@BalusC 的回答
如何在 h:inputTextarea 上设置 maxlength 属性
This is not really a RichFaces issue but concerns JSF.
It's also been answered better before. see @BalusC 's answer
How to set maxlength attribute on h:inputTextarea