if (getElement().getTagName().toLowerCase().equals("textarea")) {
// NOP no maxlenght property for textarea
} else {
- getElement().setAttribute("maxlength", "" + maxLength);
+ getElement().setPropertyInt("maxLength", maxLength);
}
} else if (maxLength != -1) {
if (getElement().getTagName().toLowerCase().equals("textarea")) {
final Window mainWin = new Window("Test app for max length feature");
setMainWindow(mainWin);
- final TextField tx = new TextField("Textfield with maxlenght 10");
- mainWin.addComponent(tx);
+ final TextField tx = new TextField(
+ "Textfield with maxlenght 10, single row");
tx.setImmediate(true);
- tx.setRows(5);
tx.setMaxLength(10);
final Label l = new Label();
mainWin.addComponent(tx);
mainWin.addComponent(b);
+
+ final TextField tx2 = new TextField(
+ "Textfield with maxlenght 10, multirow");
+ mainWin.addComponent(tx2);
+ tx2.setImmediate(true);
+ tx2.setRows(5);
+ tx2.setMaxLength(10);
+
+ Button b2 = new Button("Check value");
+ b2.addListener(new Button.ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ l.setValue("Length: " + tx2.getValue().toString().length()
+ + " Content: " + tx2.getValue());
+ }
+ });
+
+ mainWin.addComponent(tx);
+ mainWin.addComponent(b);
+
mainWin.addComponent(l);
final RichTextArea rta = new RichTextArea();