Author: rgielen
Date: Fri Jul 27 07:57:26 2007
New Revision: 560260
URL:
http://svn.apache.org/viewvc?view=rev&rev=560260
Log:
WW-2007:
Fixing problems with generated javascript idetitifiers
containing unescaped id parameter value
Added:
struts/struts2/branches/STRUTS_2_0_X/core/src/test/resources
/org/apache/struts2/views/jsp/ui/ComboBox-4.txt
Modified:
struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/
apache/struts2/components/UIBean.java
struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources
/template/simple/combobox.ftl
struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/
apache/struts2/views/jsp/ui/ComboBoxTest.java
Modified:
struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/
apache/struts2/components/UIBean.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/
STRUTS_2_0_X/core/src/main/java/org/apache/struts2/component
s/UIBean.java?view=diff&rev=560260&r1=560259&r2=
560260
============================================================
==================
---
struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/
apache/struts2/components/UIBean.java (original)
+++
struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/
apache/struts2/components/UIBean.java Fri Jul 27 07:57:26
2007
 -852,7
+852,8 
/**
* 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 :-
* <ol>
 -864,19
+865,22 
* 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));
}
StrutsTagAttribute(description="The template
directory.")
Modified:
struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources
/template/simple/combobox.ftl
URL: h
ttp://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2
_0_X/core/src/main/resources/template/simple/combobox.ftl?vi
ew=diff&rev=560260&r1=560259&r2=560260
============================================================
==================
---
struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources
/template/simple/combobox.ftl (original)
+++
struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources
/template/simple/combobox.ftl Fri Jul 27 07:57:26 2007
 -21,7
+21,7 
*/
-->
<script type="text/javascript">
- function autoPopulate_${parameters.id?html}(targetElement)
{
+ function
autoPopulate_${parameters.escapedId?html}(targetElement) {
<#if parameters.headerKey?exists &&
parameters.headerValue?exists>
if
(targetElement.options[targetElement.selectedIndex].value ==
'${parameters.headerKey?html}') {
return;
 -38,7
+38,7 
<#include
"/${parameters.templateDir}/simple/text.ftl"
/>
<br />
<#if parameters.list?exists>
-<select
onChange="autoPopulate_${parameters.id?html}(this);&quo
t;<#rt/>
+<select
onChange="autoPopulate_${parameters.escapedId?html}(thi
s);"<#rt/>
<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>
</#if>
Modified:
struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/
apache/struts2/views/jsp/ui/ComboBoxTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/b
ranches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/v
iews/jsp/ui/ComboBoxTest.java?view=diff&rev=560260&r
1=560259&r2=560260
============================================================
==================
---
struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/
apache/struts2/views/jsp/ui/ComboBoxTest.java (original)
+++
struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/
apache/struts2/views/jsp/ui/ComboBoxTest.java Fri Jul 27
07:57:26 2007
 -140,4
+140,26 
verify(ComboBoxTag.class.getResource("ComboBox-3.txt&qu
ot;));
}
+
+ public void testJsCallNamingUsesEscapedId() throws
Exception {
+ TestAction testAction = (TestAction) action;
+ testAction.setFoo("hello");
+
+ ArrayList collection = new ArrayList();
+ collection.add("foo");
+ testAction.setCollection(collection);
+
+ ComboBoxTag tag = new ComboBoxTag();
+ tag.setPageContext(pageContext);
+ tag.setLabel("mylabel");
+ tag.setName("foo");
+ tag.setId("cb.bc");
+ tag.setList("collection");
+
+ tag.doStartTag();
+ tag.doEndTag();
+
+
verify(ComboBoxTag.class.getResource("ComboBox-4.txt&qu
ot;));
+ }
+
}
Added:
struts/struts2/branches/STRUTS_2_0_X/core/src/test/resources
/org/apache/struts2/views/jsp/ui/ComboBox-4.txt
URL: http://svn.
apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/
src/test/resources/org/apache/struts2/views/jsp/ui/ComboBox-
4.txt?view=auto&rev=560260
============================================================
==================
---
struts/struts2/branches/STRUTS_2_0_X/core/src/test/resources
/org/apache/struts2/views/jsp/ui/ComboBox-4.txt (added)
+++
struts/struts2/branches/STRUTS_2_0_X/core/src/test/resources
/org/apache/struts2/views/jsp/ui/ComboBox-4.txt Fri Jul 27
07:57:26 2007
 -0,0
+1,14 
+<tr>
+ <td class="tdLabel"><label
for="cb.bc"
class="label">mylabel:</label></td>
+ <td>
+<script type="text/javascript">
+ function autoPopulate_cb_bc(targetElement) {
+ targetElement.form.elements['foo'].value=targetElement.op
tions[targetElement.selectedIndex].value;
+ }
+</script>
+<input type="text" name="foo"
value="hello"
id="cb.bc"/><br/>
+<select
onChange="autoPopulate_cb_bc(this);">
+ <option value="foo">foo</option>
+</select>
+ </td>
+</tr>
|