Fixed parsing of name for ognl when no id is specified and using name value

WW-1617


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@498091 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2007-01-20 08:44:14 +00:00
parent c0513c0e07
commit 3951b6833c
2 changed files with 19 additions and 2 deletions
@@ -872,9 +872,10 @@ public abstract class UIBean extends Component {
addParameter("id", id);
}
} else if (form != null) {
addParameter("id", form.getParameters().get("id") + "_" + escape(name));
addParameter("id", form.getParameters().get("id") + "_"
+ escape(name != null ? findString(name) : null));
} else {
addParameter("id", escape(name));
addParameter("id", escape(name != null ? findString(name) : null));
}
}
@@ -48,6 +48,22 @@ public class UIBeanTest extends StrutsTestCase {
assertEquals("txtFldId", txtFld.getParameters().get("id"));
}
public void testPopulateComponentHtmlIdWithOgnl() throws Exception {
ValueStack stack = ValueStackFactory.getFactory().createValueStack();
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("txtFldName%{'1'}");
txtFld.populateComponentHtmlId(form);
assertEquals("formId_txtFldName1", txtFld.getParameters().get("id"));
}
public void testPopulateComponentHtmlId2() throws Exception {
ValueStack stack = ValueStackFactory.getFactory().createValueStack();