如何在 h:inputTextarea 上设置 maxlength 属性 [英] How to set maxlength attribute on h:inputTextarea

查看:34
本文介绍了如何在 h:inputTextarea 上设置 maxlength 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何限制的长度?对于 它与 maxlength 属性一起工作正常.但是,该属性在 中不可用.

How can I limit the length of <h:inputTextarea>? For <h:inputText> it works fine with maxlength attribute. However, this attribute is unavailable in <h:inputTextarea>.

推荐答案

HTML5 + JSF 2.2+

如果您使用 HTML5 和 JSF 2.2+,请将其指定为 passthrough 属性.

<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">

<h:inputTextarea value="#{bean.text}" a:maxlength="2000" />

HTML5 + JSF 2.0/2.1

如果您使用的是 HTML5,但还不是 JSF 2.2,请使用 OmniFaces Html5RenderKit 以识别 JSF 2.0/2.1 中的新 HTML5 属性.

HTML5 + JSF 2.0/2.1

If you're using HTML5, but not JSF 2.2 yet, use OmniFaces Html5RenderKit to recognize new HTML5 attributes in JSF 2.0/2.1.

<h:inputTextarea value="#{bean.text}" maxlength="2000" />

HTML4

如果您使用的是 HTML4,则 HTML 本身已经不支持它.它仅支持 元素,不支持