Author: musachy
Date: Tue Jun 12 12:13:58 2007
New Revision: 546602
URL: http://svn.apache.org/viewvc?view=rev&rev=546602
Log:
WW-1981 set should use the "id" attribute like the url and bean tags
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Set.java
struts/struts2/trunk/core/src/site/resources/tags/set.html
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/SetTagTest.java
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Set.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Set.java?view=diff&rev=546602&r1=546601&r2=546602
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Set.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Set.java
Tue Jun 12 12:13:58 2007
@@ -56,7 +56,7 @@
*
* <ul>
*
- * <li>name* (String): The name of the new variable that is assigned the value
of <i>value</i></li>
+ * <li>id (String): The name of the new variable that is assigned the value of
<i>value</i></li>
*
* <li>value (Object): The value that is assigned to the variable named
<i>name</i></li>
*
@@ -71,7 +71,7 @@
*
* <pre>
* <!-- START SNIPPET: example -->
- * <s:set name="personName" value="person.name"/>
+ * <s:set id="personName" value="person.name"/>
* Hello, <s:property value="#personName"/>. How are you?
* <!-- END SNIPPET: example -->
* </pre>
@@ -103,36 +103,26 @@
body="";
- String name;
- if (altSyntax()) {
- name = findString(this.name, "name", "Name is required");
- } else {
- name = this.name;
-
- if (this.name == null) {
- throw fieldError("name", "Name is required", null);
- }
- }
-
+ //no need to throw an error, the id is required on the TLD
if ("application".equalsIgnoreCase(scope)) {
- stack.setValue("#application['" + name + "']", o);
+ stack.setValue("#application['" + id + "']", o);
} else if ("session".equalsIgnoreCase(scope)) {
- stack.setValue("#session['" + name + "']", o);
+ stack.setValue("#session['" + id + "']", o);
} else if ("request".equalsIgnoreCase(scope)) {
- stack.setValue("#request['" + name + "']", o);
+ stack.setValue("#request['" + id + "']", o);
} else if ("page".equalsIgnoreCase(scope)) {
- stack.setValue("#attr['" + name + "']", o, false);
+ stack.setValue("#attr['" + id + "']", o, false);
} else {
- stack.getContext().put(name, o);
- stack.setValue("#attr['" + name + "']", o, false);
+ stack.getContext().put(id, o);
+ stack.setValue("#attr['" + id + "']", o, false);
}
return super.end(writer, body);
}
- @StrutsTagAttribute(description=" The name of the new variable that is
assigned the value of <i>value</i>", required=true)
+ @StrutsTagAttribute(description="Deprecated. Use 'id' instead")
public void setName(String name) {
- this.name = name;
+ super.setId(name);
}
@StrutsTagAttribute(description="The scope in which to assign the
variable. Can be <b>application</b>" +
@@ -144,5 +134,10 @@
@StrutsTagAttribute(description="The value that is assigned to the
variable named <i>name</i>")
public void setValue(String value) {
this.value = value;
+ }
+
+ @StrutsTagAttribute(description="The name of the new variable that is
assigned the value of <i>value</i>", required=true)
+ public void setId(String id) {
+ super.setId(id);
}
}
Modified: struts/struts2/trunk/core/src/site/resources/tags/set.html
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/site/resources/tags/set.html?view=diff&rev=546602&r1=546601&r2=546602
==============================================================================
--- struts/struts2/trunk/core/src/site/resources/tags/set.html (original)
+++ struts/struts2/trunk/core/src/site/resources/tags/set.html Tue Jun 12
12:13:58 2007
@@ -29,19 +29,19 @@
</tr>
<tr>
<td align="left" valign="top">id</td>
- <td align="left" valign="top">false</td>
+ <td align="left"
valign="top"><strong>true</strong></td>
<td align="left" valign="top"></td>
<td align="left" valign="top">true</td>
<td align="left"
valign="top">String</td>
- <td align="left" valign="top">id for
referencing element. For UI and form tags it will be used as HTML id
attribute</td>
+ <td align="left" valign="top">The name
of the new variable that is assigned the value of <i>value</i></td>
</tr>
<tr>
<td align="left" valign="top">name</td>
- <td align="left"
valign="top"><strong>true</strong></td>
+ <td align="left" valign="top">false</td>
<td align="left" valign="top"></td>
<td align="left" valign="top">true</td>
<td align="left"
valign="top">String</td>
- <td align="left" valign="top"> The name
of the new variable that is assigned the value of <i>value</i></td>
+ <td align="left"
valign="top">Deprecated. Use 'id' instead</td>
</tr>
<tr>
<td align="left" valign="top">scope</td>
Modified:
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/SetTagTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/SetTagTest.java?view=diff&rev=546602&r1=546601&r2=546602
==============================================================================
---
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/SetTagTest.java
(original)
+++
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/SetTagTest.java
Tue Jun 12 12:13:58 2007
@@ -40,6 +40,17 @@
assertEquals("chewie", servletContext.getAttribute("foo"));
}
+
+ public void testApplicationScopeUseId() throws JspException {
+ tag.setId("foo");
+ tag.setValue("name");
+ tag.setScope("application");
+ tag.doStartTag();
+ tag.doEndTag();
+
+ assertEquals("chewie", servletContext.getAttribute("foo"));
+ }
+
public void testPageScope() throws JspException {
tag.setName("foo");
@@ -50,6 +61,16 @@
assertEquals("chewie", pageContext.getAttribute("foo"));
}
+
+ public void testPageScopeUseId() throws JspException {
+ tag.setId("foo");
+ tag.setValue("name");
+ tag.setScope("page");
+ tag.doStartTag();
+ tag.doEndTag();
+
+ assertEquals("chewie", pageContext.getAttribute("foo"));
+ }
public void testRequestScope() throws JspException {
tag.setName("foo");
@@ -59,6 +80,15 @@
tag.doEndTag();
assertEquals("chewie", request.getAttribute("foo"));
}
+
+ public void testRequestScopeUseId() throws JspException {
+ tag.setId("foo");
+ tag.setValue("name");
+ tag.setScope("request");
+ tag.doStartTag();
+ tag.doEndTag();
+ assertEquals("chewie", request.getAttribute("foo"));
+ }
public void testSessionScope() throws JspException {
tag.setName("foo");
@@ -69,6 +99,16 @@
assertEquals("chewie", session.get("foo"));
}
+
+ public void testSessionScopeUseId() throws JspException {
+ tag.setId("foo");
+ tag.setValue("name");
+ tag.setScope("session");
+ tag.doStartTag();
+ tag.doEndTag();
+
+ assertEquals("chewie", session.get("foo"));
+ }
public void testStrutsScope() throws JspException {
tag.setName("foo");
@@ -77,9 +117,24 @@
tag.doEndTag();
assertEquals("chewie", context.get("foo"));
}
+
+ public void testStrutsScopeUseId() throws JspException {
+ tag.setId("foo");
+ tag.setValue("name");
+ tag.doStartTag();
+ tag.doEndTag();
+ assertEquals("chewie", context.get("foo"));
+ }
public void testStrutsScope2() throws JspException {
tag.setName("chewie");
+ tag.doStartTag();
+ tag.doEndTag();
+ assertEquals(chewie, context.get("chewie"));
+ }
+
+ public void testStrutsScope2UseId() throws JspException {
+ tag.setId("chewie");
tag.doStartTag();
tag.doEndTag();
assertEquals(chewie, context.get("chewie"));