WW-2027 Tags that push values into the value stack should use the "var" attribute to specify the name of the variable

* Fix iterator tags

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@555056 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2007-07-10 19:40:06 +00:00
parent 479d4e98c0
commit 57dab4db8e
8 changed files with 72 additions and 32 deletions
@@ -39,11 +39,6 @@ public class StrutsBodyTagSupport extends BodyTagSupport {
private static final long serialVersionUID = -1201668454354226175L;
@StrutsTagAttribute(required=false,description="The id of the tag element")
public void setId(String string) {
super.setId(string);
}
protected boolean altSyntax() {
return ContextUtil.isUseAltSyntax(getStack().getContext());
}
@@ -46,7 +46,7 @@ import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
* <li>val* (Object) - the source to be parsed into an iterator </li>
* <li>count (Object) - the max number (Integer, Float, Double, Long, String) entries to be in the iterator</li>
* <li>separator (String) - the separator to be used in separating the <i>val</i> into entries of the iterator</li>
* <li>id (String) - the id to store the resultant iterator into page context, if such id is supplied</li>
* <li>var (String) - the name to store the resultant iterator into page context, if such name is supplied</li>
* <li>converter (Object) - the converter (must extends off IteratorGenerator.Converter interface) to convert the String entry parsed from <i>val</i> into an object</li>
* </ul>
* <!-- END SNIPPET: params -->
@@ -78,8 +78,8 @@ import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
*
* Example Three:
* <pre>
* Generate an iterator with id attribute
* &lt;s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" count="4" separator="," id="myAtt" /&gt;
* Generate an iterator with var attribute
* &lt;s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" count="4" separator="," var="myAtt" /&gt;
* &lt;%
* Iterator i = (Iterator) pageContext.getAttribute("myAtt");
* while(i.hasNext()) {
@@ -89,7 +89,7 @@ import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
* %&gt;
* </pre>
* This generates an iterator and put it in the PageContext under the key as specified
* by the id attribute.
* by the var attribute.
*
*
* Example Four:
@@ -138,7 +138,7 @@ public class IteratorGeneratorTag extends StrutsBodyTagSupport {
String separatorAttr;
String valueAttr;
String converterAttr;
String var;
IteratorGenerator iteratorGenerator = null;
@StrutsTagAttribute(type="Integer",description="The max number entries to be in the iterator")
@@ -170,13 +170,14 @@ public class IteratorGeneratorTag extends StrutsBodyTagSupport {
converterAttr = aConverter;
}
/**
* @s.tagattribute required="false" type="String"
* description="the id to store the resultant iterator into page context, if such id is supplied"
*/
@StrutsTagAttribute(description="The id to store the resultant iterator into page context, if such id is supplied")
@StrutsTagAttribute(description="Deprecated. Use 'var' instead")
public void setId(String string) {
super.setId(string);
setVar(string);
}
@StrutsTagAttribute(description="The name to store the resultant iterator into page context, if such name is supplied")
public void setVar(String var) {
this.var = var;
}
public int doStartTag() throws JspException {
@@ -236,10 +237,10 @@ public class IteratorGeneratorTag extends StrutsBodyTagSupport {
// push resulting iterator into stack
getStack().push(iteratorGenerator);
if (getId() != null && getId().length() > 0) {
if (var != null && var.length() > 0) {
// if an id is specified, we have the resulting iterator set into
// the pageContext attribute as well
pageContext.setAttribute(getId(), iteratorGenerator);
pageContext.setAttribute(var, iteratorGenerator);
}
return EVAL_BODY_INCLUDE;
@@ -37,8 +37,8 @@ import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
* <b>NOTE: JSP-TAG</b>
*
* <p>A Tag that sorts a List using a Comparator both passed in as the tag attribute.
* If 'id' attribute is specified, the sorted list will be placed into the PageContext
* attribute using the key specified by 'id'. The sorted list will ALWAYS be
* If 'var' attribute is specified, the sorted list will be placed into the PageContext
* attribute using the key specified by 'var'. The sorted list will ALWAYS be
* pushed into the stack and poped at the end of this tag.</p>
*
* <!-- END SNIPPET: javadoc -->
@@ -94,6 +94,7 @@ public class SortIteratorTag extends StrutsBodyTagSupport {
String comparatorAttr;
String sourceAttr;
String var;
SortIteratorFilter sortIteratorFilter = null;
@@ -106,6 +107,16 @@ public class SortIteratorTag extends StrutsBodyTagSupport {
public void setSource(String source) {
sourceAttr = source;
}
@StrutsTagAttribute(description="Deprecated. Use 'var' instead")
public void setId(String string) {
setVar(string);
}
@StrutsTagAttribute(description="The name to store the resultant iterator into page context, if such name is supplied")
public void setVar(String var) {
this.var = var;
}
public int doStartTag() throws JspException {
// Source
@@ -134,8 +145,8 @@ public class SortIteratorTag extends StrutsBodyTagSupport {
// push sorted iterator into stack, so nexted tag have access to it
getStack().push(sortIteratorFilter);
if (getId() != null && getId().length() > 0) {
pageContext.setAttribute(getId(), sortIteratorFilter);
if (var != null && var.length() > 0) {
pageContext.setAttribute(var, sortIteratorFilter);
}
return EVAL_BODY_INCLUDE;
@@ -46,7 +46,7 @@ import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
* <li>source* (Object) - Indicate the source of which the resulting subset iterator is to be derived base on</li>
* <li>start (Object) - Indicate the starting index (eg. first entry is 0) of entries in the source to be available as the first entry in the resulting subset iterator</li>
* <li>decider (Object) - Extension to plug-in a decider to determine if that particular entry is to be included in the resulting subset iterator</li>
* <li>id (String) - Indicate the pageContext attribute id to store the resultant subset iterator in</li>
* <li>var (String) - Indicate the pageContext attribute name to store the resultant subset iterator in</li>
* </ul>
* <!-- END SNIPPET: params -->
*
@@ -121,8 +121,8 @@ import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
*
* <pre>
* <!-- START SNIPPET: example4 -->
* &lt;!-- D: List with id --&gt;
* &lt;s:subset id="mySubset" source="myList" count="13" start="3" /&gt;
* &lt;!-- D: List with var --&gt;
* &lt;s:subset var="mySubset" source="myList" count="13" start="3" /&gt;
* &lt;%
* Iterator i = (Iterator) pageContext.getAttribute("mySubset");
* while(i.hasNext()) {
@@ -159,7 +159,7 @@ public class SubsetIteratorTag extends StrutsBodyTagSupport {
String sourceAttr;
String startAttr;
String deciderAttr;
String var;
SubsetIteratorFilter subsetIteratorFilter = null;
@@ -189,6 +189,15 @@ public class SubsetIteratorTag extends StrutsBodyTagSupport {
deciderAttr = decider;
}
@StrutsTagAttribute(description="Deprecated. Use 'var' instead")
public void setId(String string) {
setVar(string);
}
@StrutsTagAttribute(description="The name to store the resultant iterator into page context, if such name is supplied")
public void setVar(String var) {
this.var = var;
}
public int doStartTag() throws JspException {
@@ -271,8 +280,8 @@ public class SubsetIteratorTag extends StrutsBodyTagSupport {
subsetIteratorFilter.execute();
getStack().push(subsetIteratorFilter);
if (getId() != null) {
pageContext.setAttribute(getId(), subsetIteratorFilter);
if (var != null && var.length() > 0) {
pageContext.setAttribute(var, subsetIteratorFilter);
}
return EVAL_BODY_INCLUDE;
+9 -1
View File
@@ -49,7 +49,7 @@ Please do not edit it directly.
<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 id to store the resultant iterator into page context, if such id is supplied</td>
<td align="left" valign="top">Deprecated. Use 'var' instead</td>
</tr>
<tr>
<td align="left" valign="top">separator</td>
@@ -67,6 +67,14 @@ Please do not edit it directly.
<td align="left" valign="top">String</td>
<td align="left" valign="top">The source to be parsed into an iterator</td>
</tr>
<tr>
<td align="left" valign="top">var</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 to store the resultant iterator into page context, if such name is supplied</td>
</tr>
</table>
<!-- END SNIPPET: tagattributes -->
</body>
+1 -1
View File
@@ -61,7 +61,7 @@ Please do not edit it directly.
</tr>
<tr>
<td align="left" valign="top">var</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>
+9 -1
View File
@@ -41,7 +41,7 @@ Please do not edit it directly.
<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 id of the tag element</td>
<td align="left" valign="top">Deprecated. Use 'var' instead</td>
</tr>
<tr>
<td align="left" valign="top">source</td>
@@ -51,6 +51,14 @@ Please do not edit it directly.
<td align="left" valign="top">String</td>
<td align="left" valign="top">The iterable source to sort</td>
</tr>
<tr>
<td align="left" valign="top">var</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 to store the resultant iterator into page context, if such name is supplied</td>
</tr>
</table>
<!-- END SNIPPET: tagattributes -->
</body>
+9 -1
View File
@@ -49,7 +49,7 @@ Please do not edit it directly.
<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 id of the tag element</td>
<td align="left" valign="top">Deprecated. Use 'var' instead</td>
</tr>
<tr>
<td align="left" valign="top">source</td>
@@ -67,6 +67,14 @@ Please do not edit it directly.
<td align="left" valign="top">Integer</td>
<td align="left" valign="top">Indicate the starting index (eg. first entry is 0) of entries in the source to be available as the first entry in the resulting subset iterator</td>
</tr>
<tr>
<td align="left" valign="top">var</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 to store the resultant iterator into page context, if such name is supplied</td>
</tr>
</table>
<!-- END SNIPPET: tagattributes -->
</body>