mirror of
https://github.com/apache/struts.git
synced 2026-08-31 11:24:28 +00:00
WW-769
- UITags do not evaluate id attribute git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@431149 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -131,14 +131,14 @@ public class Form extends ClosingUIBean {
|
||||
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 @@ public class Form extends ClosingUIBean {
|
||||
String namespace = determineNamespace(this.namespace, getStack(),
|
||||
request);
|
||||
evaluateExtraParamsServletRequest(action, namespace, isAjax);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (onsubmit != null) {
|
||||
addParameter("onsubmit", findString(onsubmit));
|
||||
@@ -179,6 +179,27 @@ public class Form extends ClosingUIBean {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isAjax
|
||||
|
||||
@@ -40,7 +40,9 @@ 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";
|
||||
}
|
||||
@@ -51,7 +53,7 @@ public abstract class FormButton extends UIBean {
|
||||
submitType = type;
|
||||
}
|
||||
|
||||
super.evaluateParams();
|
||||
//super.evaluateParams();
|
||||
|
||||
addParameter("type", submitType);
|
||||
|
||||
@@ -78,12 +80,55 @@ public abstract class FormButton extends UIBean {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether the concrete button supports the type "image".
|
||||
*
|
||||
* @return <tt>true</tt> if type image is supported.
|
||||
*/
|
||||
* Indicate whether the concrete button supports the type "image".
|
||||
*
|
||||
* @return <tt>true</tt> if type image is supported.
|
||||
*/
|
||||
protected abstract boolean supportsImageType();
|
||||
|
||||
/**
|
||||
|
||||
@@ -179,12 +179,20 @@ public class Submit extends FormButton {
|
||||
}
|
||||
|
||||
public void evaluateParams() {
|
||||
|
||||
if (value == null) {
|
||||
if (value == null) {
|
||||
value = "Submit";
|
||||
}
|
||||
super.evaluateParams();
|
||||
}
|
||||
|
||||
public void evaluateExtraParams() {
|
||||
super.evaluateExtraParams();
|
||||
|
||||
super.evaluateParams();
|
||||
/* if (value == null) {
|
||||
value = "Submit";
|
||||
}*/
|
||||
|
||||
//super.evaluateParams();
|
||||
|
||||
if (null != src) {
|
||||
addParameter("src", findString(src));
|
||||
|
||||
@@ -689,18 +689,8 @@ public abstract class UIBean extends Component {
|
||||
|
||||
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 @@ public abstract class UIBean extends Component {
|
||||
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.
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user