开发者

JSF h:inputTextarea to HTML textArea - passing maxlength attribute

开发者 https://www.devze.com 2023-04-01 03:28 出处:网络
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?

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" />


maxlength doesn't exists on h:inputTextarea (see doc).

To add a validator message, try

<h:inputTextarea >
  <f:validateLength maximum="100"></f:validateLength>
</h:inputTextarea>


Our solution was to put an extra span immediately in front of the textarea that contained the maxlength number.

<span class="maxlength">35</span>

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):

$('span.maxlength').each(function(){
    $this = $(this);
    $this.next('textarea').attr('maxlength',$this.html());
    $this.remove();
});

Once that's done, run your other JavaScript that limits typing in textareas.

Hacky? Yes. But JSF not supporting maxlength is hacky.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消