html:textarea の struts 1 タグはこちら
maxlength 属性が表示されません。ユーザーが 100 文字を超えて入力できないようにするにはどうすればよいですか? また、struts 1 がそのような基本的な属性を省略したのはなぜですか?
JS を使用して属性を追加します。
テキストエリアの後に次のようなものを置きます。
<script type="text/javascript">
document.getElementById('textarea-id').setAttribute('maxlength', '512');
</script>
この「基本属性」は IE 10 より前の IE でもサポートされておらず、HTML 5 で追加されたためです。
Struts 1 はそれよりかなり前にリリースされ、EOL となり、新しいリリースはしばらくありませんでした。Struts 1.2 の最後のリリースが 2006 年っぽいことを覚えておいてください。
TLD を抽出して変更し、JSP 2.0 で任意の属性を許可することができます。
<dynamic-attributes>true</dynamic-attributes>
styleId
に属性を追加するとhtml:textarea
、ストラットは属性を受け入れませんid
。その後、Javascriptを追加して長さを制限します
<html:textarea styleId="contactText" property="contactText" cols="55" rows="10"/>
<script type="text/javascript">
document.getElementById('contactText').setAttribute('maxlength', '10');
</script>
maxlength="100"
JSP のテキスト領域または入力内で使用するか、validator.xml をカスタマイズする必要があります。
validator.xml で:
<field property="propertyname" depends="maxlength">
<var-name>maxlength</var-name>
<var-value>100</var-value>
</var>
<msg key="propertyname.maxlength" name="maxlength" />
</field>
Application.proprties:
propertyname.maxlength = <tr><td colspan\="2" class\="note">Please make sure that FieldName is only maximum 100 characters.</td></tr>