You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matt Williams <ma...@yahoo.com.INVALID> on 2014/06/03 19:17:54 UTC
Struts2 iterator twice for select tag
I am using struts 2.1.8. I am extending the "org.apache.struts2.components.Select" tag and writing my own "select.ftl" (freemarker template).
I need to iterate over the parameter "parameters.list" twice.
Example:
<@s.iterator value="parameters.list">
<div>loop1</div>
</...@s.iterator>
<@s.iterator value="parameters.list">
<div>loop2</div>
</...@s.iterator>
However, the second iterator doesn't loop. I think the "parameters.list" is an Iterator object so it is already at the end (created by org.apache.struts2.util.MakeIterator.convert(Object)).
Is there a way?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 iterator twice for select tag
Posted by Matt Williams <ma...@yahoo.com.INVALID>.
I ended up overriding the 'evaluateExtraParams()' method and performing the exact same logic that is in the ListUIBean.evaluateExtraParams() to set a new parameter called 'listCopy' to use in the extra iterator.
Code:
@Override
public void evaluateExtraParams() {
super.evaluateExtraParams();
//This is the same logic as in 'evaluateExtraParams()' but I need a copy of the 'list'.
Object value = null;
if (list == null) {
list = parameters.get("list");
}
if (list instanceof String) {
value = findValue((String) list);
} else if (list instanceof Collection) {
value = list;
} else if (MakeIterator.isIterable(list)) {
value = MakeIterator.convert(list);
}
if (value == null) {
if (throwExceptionOnNullValueAttribute) {
// will throw an exception if not found
value = findValue((list == null) ? (String) list : list.toString(), "list",
"The requested list key '" + list + "' could not be resolved as a collection/array/map/enumeration/iterator"+
" type. " +
"Example: people or people.{name}");
} else {
// ww-1010, allows value with null value to be compatible with ww
// 2.1.7 behavior
value = findValue((list == null)?(String) list:list.toString());
}
}
if (value instanceof Collection) {
addParameter("listCopy", value);
} else {
addParameter("listCopy", MakeIterator.convert(value));
}
}
Matt
On Wednesday, June 4, 2014 2:45 AM, Lukasz Lenart <lu...@apache.org> wrote:
2014-06-03 19:17 GMT+02:00 Matt Williams <ma...@yahoo.com.invalid>:
>
> I am using struts 2.1.8. I am extending the "org.apache.struts2.components.Select" tag and writing my own "select.ftl" (freemarker template).
>
> I need to iterate over the parameter "parameters.list" twice.
>
> Example:
> <@s.iterator value="parameters.list">
> <div>loop1</div>
> </...@s.iterator>
> <@s.iterator value="parameters.list">
> <div>loop2</div>
> </...@s.iterator>
>
> However, the second iterator doesn't loop. I think the "parameters.list" is an Iterator object so it is already at the end (created by org.apache.struts2.util.MakeIterator.convert(Object)).
>
> Is there a way?
Use <#assign> and create a copy?
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 iterator twice for select tag
Posted by Lukasz Lenart <lu...@apache.org>.
2014-06-03 19:17 GMT+02:00 Matt Williams <ma...@yahoo.com.invalid>:
>
> I am using struts 2.1.8. I am extending the "org.apache.struts2.components.Select" tag and writing my own "select.ftl" (freemarker template).
>
> I need to iterate over the parameter "parameters.list" twice.
>
> Example:
> <@s.iterator value="parameters.list">
> <div>loop1</div>
> </...@s.iterator>
> <@s.iterator value="parameters.list">
> <div>loop2</div>
> </...@s.iterator>
>
> However, the second iterator doesn't loop. I think the "parameters.list" is an Iterator object so it is already at the end (created by org.apache.struts2.util.MakeIterator.convert(Object)).
>
> Is there a way?
Use <#assign> and create a copy?
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 iterator twice for select tag
Posted by Paul Benedict <pb...@apache.org>.
Maybe you found a bug. Hopefully Struts cleans up its iterator when the tag
finishes. Maybe you can look into the source code to find out for us.
Cheers,
Paul
On Tue, Jun 3, 2014 at 12:17 PM, Matt Williams <
mattwms1998cce@yahoo.com.invalid> wrote:
>
> I am using struts 2.1.8. I am extending the
> "org.apache.struts2.components.Select" tag and writing my own "select.ftl"
> (freemarker template).
>
> I need to iterate over the parameter "parameters.list" twice.
>
> Example:
> <@s.iterator value="parameters.list">
> <div>loop1</div>
> </...@s.iterator>
> <@s.iterator value="parameters.list">
> <div>loop2</div>
> </...@s.iterator>
>
> However, the second iterator doesn't loop. I think the "parameters.list"
> is an Iterator object so it is already at the end (created by
> org.apache.struts2.util.MakeIterator.convert(Object)).
>
> Is there a way?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>