You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by tm...@apache.org on 2006/08/13 08:45:28 UTC
svn commit: r431149 - in /struts/struts2/trunk/core/src:
main/java/org/apache/struts2/components/
test/java/org/apache/struts2/components/
Author: tmjee
Date: Sat Aug 12 23:45:27 2006
New Revision: 431149
URL: http://svn.apache.org/viewvc?rev=431149&view=rev
Log:
WW-769
- UITags do not evaluate id attribute
Added:
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/FormButtonTest.java (with props)
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java (with props)
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java?rev=431149&r1=431148&r2=431149&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java Sat Aug 12 23:45:27 2006
@@ -131,14 +131,14 @@
protected void evaluateExtraParams() {
super.evaluateExtraParams();
- boolean isAjax = "ajax".equalsIgnoreCase(this.theme);
+ //boolean isAjax = "ajax".equalsIgnoreCase(this.theme);
if (validate != null) {
addParameter("validate", findValue(validate, Boolean.class));
}
// calculate the action and namespace
- String action = null;
+ /*String action = null;
if (this.action != null) {
// if it isn't specified, we'll make somethig up
action = findString(this.action);
@@ -150,7 +150,7 @@
String namespace = determineNamespace(this.namespace, getStack(),
request);
evaluateExtraParamsServletRequest(action, namespace, isAjax);
- }
+ }*/
if (onsubmit != null) {
addParameter("onsubmit", findString(onsubmit));
@@ -177,6 +177,27 @@
if (!parameters.containsKey("tagNames")) {
// we have this if check so we don't do this twice (on open and close of the template)
addParameter("tagNames", new ArrayList());
+ }
+ }
+
+ protected void populateComponentHtmlId(Form form) {
+ boolean isAjax = "ajax".equalsIgnoreCase(this.theme);
+
+ String action = null;
+ if (this.action != null) {
+ // if it isn't specified, we'll make somethig up
+ action = findString(this.action);
+ }
+
+ if (id != null) {
+ addParameter("id", escape(id));
+ }
+ if (Dispatcher.getInstance().isPortletSupportActive() && PortletActionContext.isPortletRequest()) {
+ evaluateExtraParamsPortletRequest(namespace, action);
+ } else {
+ String namespace = determineNamespace(this.namespace, getStack(),
+ request);
+ evaluateExtraParamsServletRequest(action, namespace, isAjax);
}
}
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java?rev=431149&r1=431148&r2=431149&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FormButton.java Sat Aug 12 23:45:27 2006
@@ -40,7 +40,9 @@
super(stack, request, response);
}
- public void evaluateParams() {
+ //public void evaluateParams() {
+ public void evaluateExtraParams() {
+ super.evaluateExtraParams();
if (align == null) {
align = "right";
}
@@ -51,7 +53,7 @@
submitType = type;
}
- super.evaluateParams();
+ //super.evaluateParams();
addParameter("type", submitType);
@@ -78,12 +80,55 @@
addParameter("align", findString(align));
}
-
+
/**
- * Indicate whether the concrete button supports the type "image".
- *
- * @return <tt>true</tt> if type image is supported.
+ * Override UIBean's implementation, such that component Html id is determined
+ * in the following order :-
+ * <ol>
+ * <li>This component id attribute</li>
+ * <li>[containing_form_id]_[this_component_name]</li>
+ * <li>[containing_form_id]_[this_component_action]_[this_component_method]</li>
+ * <li>[containing_form_id]_[this_component_method]</li>
+ * <li>[this_component_name]</li>
+ * <li>[this_component_action]_[this_component_method]</li>
+ * <li>[this_component_method]</li>
+ * </ol>
*/
+ protected void populateComponentHtmlId(Form form) {
+ String _tmp_id = "";
+ if (id != null) {
+ // this check is needed for backwards compatibility with 2.1.x
+ if (altSyntax()) {
+ _tmp_id = findString(id);
+ } else {
+ _tmp_id = id;
+ }
+ }
+ else {
+ if (form != null && form.getParameters().get("id") != null) {
+ _tmp_id = _tmp_id + form.getParameters().get("id").toString() + "_";
+ }
+ if (name != null) {
+ _tmp_id = _tmp_id + escape(name);
+ } else if (action != null || method != null){
+ if (action != null) {
+ _tmp_id = _tmp_id + escape(action);
+ }
+ if (method != null) {
+ _tmp_id = _tmp_id + "_" + escape(method);
+ }
+ } else {
+ _tmp_id = _tmp_id + hashCode();
+ }
+ }
+ addParameter("id", _tmp_id);
+ }
+
+ /**
+ * Indicate whether the concrete button supports the type "image".
+ *
+ * @return <tt>true</tt> if type image is supported.
+ */
protected abstract boolean supportsImageType();
/**
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java?rev=431149&r1=431148&r2=431149&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Submit.java Sat Aug 12 23:45:27 2006
@@ -179,12 +179,20 @@
}
public void evaluateParams() {
-
- if (value == null) {
+ if (value == null) {
value = "Submit";
}
+ super.evaluateParams();
+ }
+
+ public void evaluateExtraParams() {
+ super.evaluateExtraParams();
+
+ /* if (value == null) {
+ value = "Submit";
+ }*/
- super.evaluateParams();
+ //super.evaluateParams();
if (null != src) {
addParameter("src", findString(src));
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java?rev=431149&r1=431148&r2=431149&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java Sat Aug 12 23:45:27 2006
@@ -689,18 +689,8 @@
final Form form = (Form) findAncestor(Form.class);
- if (id != null) {
- // this check is needed for backwards compatibility with 2.1.x
- if (altSyntax()) {
- addParameter("id", findString(id));
- } else {
- addParameter("id", id);
- }
- } else if (form != null) {
- addParameter("id", form.getParameters().get("id") + "_" + escape(name));
- } else {
- addParameter("id", escape(name));
- }
+ // create HTML id element
+ populateComponentHtmlId(form);
if (form != null ) {
addParameter("form", form.getParameters());
@@ -815,6 +805,34 @@
return tooltipConfig;
}
+ /**
+ * Create HTML id element for the component and populate this component parmaeter
+ * map.
+ *
+ * The order is as follows :-
+ * <ol>
+ * <li>This component id attribute</li>
+ * <li>[containing_form_id]_[this_component_name]</li>
+ * <li>[this_component_name]</li>
+ * </ol>
+ *
+ * @param form
+ */
+ protected void populateComponentHtmlId(Form form) {
+ if (id != null) {
+ // this check is needed for backwards compatibility with 2.1.x
+ if (altSyntax()) {
+ addParameter("id", findString(id));
+ } else {
+ addParameter("id", id);
+ }
+ } else if (form != null) {
+ addParameter("id", form.getParameters().get("id") + "_" + escape(name));
+ } else {
+ addParameter("id", escape(name));
+ }
+ }
+
/**
* The template directory.
Added: struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/FormButtonTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/FormButtonTest.java?rev=431149&view=auto
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/FormButtonTest.java (added)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/FormButtonTest.java Sat Aug 12 23:45:27 2006
@@ -0,0 +1,122 @@
+/*
+ * $Id: FormButton.java 420385 2006-07-10 00:57:05Z tmjee $
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.components;
+
+import org.apache.struts2.StrutsTestCase;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import com.opensymphony.xwork2.util.OgnlValueStack;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @version $Date$ $Id$
+ */
+public class FormButtonTest extends StrutsTestCase {
+
+ public void testPopulateComponentHtmlId1() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ MockHttpServletResponse res = new MockHttpServletResponse();
+ OgnlValueStack stack = new OgnlValueStack();
+
+ Form form = new Form(stack, req, res);
+ form.getParameters().put("id", "formId");
+
+ Submit submit = new Submit(stack, req, res);
+ submit.setId("submitId");
+
+ submit.populateComponentHtmlId(form);
+
+ assertEquals("submitId", submit.getParameters().get("id"));
+ }
+
+ public void testPopulateComponentHtmlId2() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ MockHttpServletResponse res = new MockHttpServletResponse();
+ OgnlValueStack stack = new OgnlValueStack();
+
+ Form form = new Form(stack, req, res);
+ form.getParameters().put("id", "formId");
+
+ Submit submit = new Submit(stack, req, res);
+ submit.setName("submitName");
+
+ submit.populateComponentHtmlId(form);
+
+ assertEquals("formId_submitName", submit.getParameters().get("id"));
+ }
+
+ public void testPopulateComponentHtmlId3() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ MockHttpServletResponse res = new MockHttpServletResponse();
+ OgnlValueStack stack = new OgnlValueStack();
+
+ Form form = new Form(stack, req, res);
+ form.getParameters().put("id", "formId");
+
+ Submit submit = new Submit(stack, req, res);
+ submit.setAction("submitAction");
+ submit.setMethod("submitMethod");
+
+ submit.populateComponentHtmlId(form);
+
+ assertEquals("formId_submitAction_submitMethod", submit.getParameters().get("id"));
+ }
+
+ public void testPopulateComponentHtmlId4() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ MockHttpServletResponse res = new MockHttpServletResponse();
+ OgnlValueStack stack = new OgnlValueStack();
+
+ Submit submit = new Submit(stack, req, res);
+ submit.setId("submitId");
+
+ submit.populateComponentHtmlId(null);
+
+ assertEquals("submitId", submit.getParameters().get("id"));
+ }
+
+ public void testPopulateComponentHtmlId5() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ MockHttpServletResponse res = new MockHttpServletResponse();
+ OgnlValueStack stack = new OgnlValueStack();
+
+ Submit submit = new Submit(stack, req, res);
+ submit.setName("submitName");
+
+ submit.populateComponentHtmlId(null);
+
+ assertEquals("submitName", submit.getParameters().get("id"));
+ }
+
+ public void testPopulateComponentHtmlId6() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ MockHttpServletResponse res = new MockHttpServletResponse();
+ OgnlValueStack stack = new OgnlValueStack();
+
+ Submit submit = new Submit(stack, req, res);
+ submit.setAction("submitAction");
+ submit.setMethod("submitMethod");
+
+ submit.populateComponentHtmlId(null);
+
+ assertEquals("submitAction_submitMethod", submit.getParameters().get("id"));
+ }
+}
Propchange: struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/FormButtonTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java?rev=431149&view=auto
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java (added)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java Sat Aug 12 23:45:27 2006
@@ -0,0 +1,63 @@
+/*
+ * $Id: StrutsTestCase.java 425615 2006-07-26 04:33:53Z tmjee $
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.components;
+
+import org.apache.struts2.StrutsTestCase;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import com.opensymphony.xwork2.util.OgnlValueStack;
+
+/**
+ *
+ * @version $Date$ $Id$
+ */
+public class UIBeanTest extends StrutsTestCase {
+
+ public void testPopulateComponentHtmlId1() 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.setId("txtFldId");
+
+ txtFld.populateComponentHtmlId(form);
+
+ assertEquals("txtFldId", txtFld.getParameters().get("id"));
+ }
+
+ public void testPopulateComponentHtmlId2() 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("txtFldName");
+
+ txtFld.populateComponentHtmlId(form);
+
+ assertEquals("formId_txtFldName", txtFld.getParameters().get("id"));
+ }
+}
Propchange: struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
------------------------------------------------------------------------------
svn:eol-style = native