From 0875a59f3312465eb2abf097b610b01dbb250c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Gielen?= Date: Fri, 27 Jul 2007 14:56:11 +0000 Subject: [PATCH] WW-2007: Fixing problems with generated javascript idetitifiers containing unescaped id parameter value git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@560258 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/struts2/components/UIBean.java | 18 +++++++++------ .../resources/template/simple/combobox.ftl | 6 ++--- .../struts2/views/jsp/ui/ComboBoxTest.java | 22 +++++++++++++++++++ .../struts2/views/jsp/ui/ComboBox-4.txt | 14 ++++++++++++ 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/ComboBox-4.txt diff --git a/core/src/main/java/org/apache/struts2/components/UIBean.java b/core/src/main/java/org/apache/struts2/components/UIBean.java index 28e22f7dc..49afcde2a 100644 --- a/core/src/main/java/org/apache/struts2/components/UIBean.java +++ b/core/src/main/java/org/apache/struts2/components/UIBean.java @@ -902,7 +902,8 @@ public abstract class UIBean extends Component { /** * Create HTML id element for the component and populate this component parmaeter - * map. + * map. Additionally, a parameter named escapedId is populated which contains the found id value filtered by + * {@link #escape(String)}, needed eg. for naming Javascript identifiers based on the id value. * * The order is as follows :- *
    @@ -914,21 +915,24 @@ public abstract class UIBean extends Component { * @param form */ protected void populateComponentHtmlId(Form form) { + String tryId; if (id != null) { // this check is needed for backwards compatibility with 2.1.x if (altSyntax()) { - addParameter("id", findString(id)); + tryId = findString(id); } else { - addParameter("id", id); + tryId = id; } } else if (form != null) { - addParameter("id", form.getParameters().get("id") + "_" - + escape(name != null ? findString(name) : null)); + tryId = form.getParameters().get("id") + "_" + + escape(name != null ? findString(name) : null); } else { - addParameter("id", escape(name != null ? findString(name) : null)); + tryId = escape(name != null ? findString(name) : null); } + addParameter("id", tryId); + addParameter("escapedId", escape(tryId)); } - + /** * Get's the id for referencing element. * @return the id for referencing element. diff --git a/core/src/main/resources/template/simple/combobox.ftl b/core/src/main/resources/template/simple/combobox.ftl index eb760dd65..475e05caf 100644 --- a/core/src/main/resources/template/simple/combobox.ftl +++ b/core/src/main/resources/template/simple/combobox.ftl @@ -21,11 +21,11 @@ */ --> +
    + + +