Commits

Anonymous committed 337333f

WW-1360 - evaluated name against ognl stack when generating id from the uibean name

Contributed By: Joseph Pemberton
Reviewed By: Tom Schneider and Rainer Hermanns

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2843573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 6afc00f

Comments (0)

Files changed (2)

File src/java/com/opensymphony/webwork/components/UIBean.java

      * @param form
      */
     protected void populateComponentHtmlId(Form form) {
-    	if (id != null) {
+    	if(id != null) {
             // this check is needed for backwards compatibility with 2.1.x
-            if (altSyntax()) {
+            if(altSyntax()) {
                 addParameter("id", findString(id));
             } else {
                 addParameter("id", id);
             }
-        } else if (form != null) {
-            addParameter("id", form.getParameters().get("id") + "_" + escape(name));
+        } else if(form != null) {
+            addParameter("id", form.getParameters().get("id") + "_"
+                + escape(name == null ? null : findString(name)));
         } else {
-            addParameter("id", escape(name));
+            addParameter("id", escape(name == null ? null : findString(name)));
         }
     }
 

File src/test/com/opensymphony/webwork/components/UIBeanTest.java

 		
 		assertEquals("formId_txtFldName", txtFld.getParameters().get("id"));
 	}
+
+        public void testPopulateComponentHtmlId3() throws Exception {
+                OgnlValueStack stack = new OgnlValueStack();
+                MockHttpServletRequest req = new MockHttpServletRequest();
+                MockHttpServletResponse res = new MockHttpServletResponse();
+                
+                Form form = new Form(stack, req, res);
+                form.getParameters().put("id", "formId");
+                
+                TextField txtFld = new TextField(stack, req, res);
+                txtFld.setName("%{1 + 1}");
+                
+                txtFld.populateComponentHtmlId(form);
+                
+                assertEquals("formId_2", txtFld.getParameters().get("id"));
+        }
 }