Commits

Anonymous committed 756683d

UITags do not evaluate id attribute

Issue number: WW-769
Obtained from:
Submitted by:
Reviewed by:

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

Comments (0)

Files changed (6)

src/java/com/opensymphony/webwork/components/Form.java

     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);
             String namespace = determineNamespace(this.namespace, getStack(),
                     request);
             evaluateExtraParamsServletRequest(action, namespace, isAjax);
-        }
+        }*/
 
         if (onsubmit != null) {
             addParameter("onsubmit", findString(onsubmit));
         }
     }
 
+    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 (DispatcherUtils.isPortletSupportActive() && PortletActionContext.isPortletRequest()) {
+            evaluateExtraParamsPortletRequest(namespace, action);
+        } else {
+            String namespace = determineNamespace(this.namespace, getStack(),
+                    request);
+            evaluateExtraParamsServletRequest(action, namespace, isAjax);
+        }
+    }
+    
     /**
      * @param isAjax
      * @param namespace

src/java/com/opensymphony/webwork/components/FormButton.java

  * FormButton.
  *
  * @author <a href="mailto:gielen@it-neering.net">Rene Gielen</a>
+ * @author tm_jee
  */
 
 public abstract class FormButton extends UIBean {
         super(stack, request, response);
     }
 
-    public void evaluateParams() {
+    //public void evaluateParams() {
+    public void evaluateExtraParams() {
+    	super.evaluateExtraParams();
         if (align == null) {
             align = "right";
         }
             submitType = type;
         }
 
-        super.evaluateParams();
+        //super.evaluateParams();
 
         addParameter("type", submitType);
 
         }
 
         addParameter("align", findString(align));
-
+    }
+    
+    /**
+     * 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);
     }
 
     /**

src/java/com/opensymphony/webwork/components/Submit.java

     }
 
     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));

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

 
         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());
     	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));
+        }
+    }
 
 
     /**

src/test/com/opensymphony/webwork/components/FormButtonTest.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.components;
+
+import com.opensymphony.webwork.components.Form;
+import com.opensymphony.webwork.components.Submit;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import com.opensymphony.webwork.WebWorkTestCase;
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+/**
+ * 
+ * @author tm_jee
+ * @version $Date$ $Id$
+ */
+public class FormButtonTest extends WebWorkTestCase {
+	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"));
+	}
+}

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.components;
+
+import com.opensymphony.webwork.components.Form;
+import com.opensymphony.webwork.components.TextField;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import com.opensymphony.webwork.WebWorkTestCase;
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+/**
+ * 
+ * @author tm_jee
+ * @version $Date$ $Id$
+ */
+public class UIBeanTest extends WebWorkTestCase {
+	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"));
+	}
+}