From 40f2c4b5773a6f80ec285a4a0c5ddc1c3dfb34fe Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Tue, 13 Mar 2012 15:02:40 +0100 Subject: [PATCH] OO-144: make possible to check only the visible length of string without subtle encoding issues (which are only databse relevant) --- .../form/flexible/elements/TextElement.java | 7 +++++++ .../flexible/impl/elements/AbstractTextElement.java | 12 ++++++++++-- .../olat/course/editor/NodeConfigFormController.java | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java index 1b76906b6a3..350ea08680d 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java @@ -145,4 +145,11 @@ public interface TextElement extends FormItem{ */ public void setMaxLength(int maxLength); + /** + * Check the visible length of the text (can be used for datas saved in XML file + * but not for DB) + * @param checkVisibleLength + */ + public void setCheckVisibleLength(boolean checkVisibleLength); + } \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java index 6e519d3baad..afa0e37e605 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java @@ -75,6 +75,7 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl private int notLongerLength; protected int displaySize; protected int maxlength = -1; //default no maxlength restriction + protected boolean checkVisibleLength = false; private String notLongerThanErrorKey; private String checkForOtherValue; private String otherValueErrorKey; @@ -204,7 +205,10 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl this.maxlength = maxLength; } - + public void setCheckVisibleLength(boolean checkVisibleLength) { + this.checkVisibleLength = checkVisibleLength; + } + /** * @param errorKey * @return @@ -245,7 +249,11 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl private boolean notLongerThan(){ boolean lengthError = false; try { - if (value.length() > notLongerLength || value.getBytes("UTF-8").length > notLongerLength) { + if(checkVisibleLength) { + if (value.length() > notLongerLength) { + lengthError = true; + } + } else if (value.length() > notLongerLength || value.getBytes("UTF-8").length > notLongerLength) { lengthError = true; } } catch (UnsupportedEncodingException e) { diff --git a/src/main/java/org/olat/course/editor/NodeConfigFormController.java b/src/main/java/org/olat/course/editor/NodeConfigFormController.java index a5956863568..0ccff3e7d68 100644 --- a/src/main/java/org/olat/course/editor/NodeConfigFormController.java +++ b/src/main/java/org/olat/course/editor/NodeConfigFormController.java @@ -145,6 +145,7 @@ public class NodeConfigFormController extends FormBasicController { // add the short title text input element shortTitle = uifactory.addTextElement("nodeConfigForm.menutitle", "nodeConfigForm.menutitle", SHORT_TITLE_MAX_LENGTH, (menuTitle == null ? "": menuTitle), formLayout); shortTitle.setMandatory(true); + shortTitle.setCheckVisibleLength(true); // add the title input text element title = uifactory.addTextElement("nodeConfigForm.displaytitle", "nodeConfigForm.displaytitle", 255, (displayTitle==null? "": displayTitle), formLayout); -- GitLab