You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Troy Bull <tr...@uni.edu> on 2005/10/20 17:26:13 UTC
Problems with Iterator tag Please Help
Hello
I have a situation here. I have an ArrayList of DTO objects in session.
<%
ArrayList rows = (ArrayList) session.getAttribute("rows");
if (rows != null) {
Iterator i = rows.iterator();
while (i.hasNext())
{
NibuSrchVLocalDTO debug = (NibuSrchVLocalDTO)i.next();
out.println("Name: " + debug.getFullName() + "<BR>");
}
}
%>
This code here (scriptlet above this line) works perfectly but
<logic:present name="rows" scope="session">
<logic:iterate id="row" scope="session"
collection="rows">Hi</logic:iterate>
</logic:present>
this code here with teh iterate tag does not it gives me the following
error:
javax.servlet.jsp.JspException: Cannot create iterator for this collection
at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:310)
at _search._jspService(search.jsp:96)
[/search.jsp]
I have these 2 code fragments in the same JSP right next to each other,
I tested by removing one fragment at a time. Any pointers would be greatly appreciated.
thanks in advance
troy
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: Problems with Iterator tag Please Help
Posted by Dave Newton <ne...@pingsite.com>.
Murray Collingwood wrote:
>Sometime it's just hard not to say anything. There are lots of different options for
>making this work and you don't have to change to JSTL to do it. The logic:iterate tag is
>absolutely fine, you just have to get the right parameter names.
>
>
I'm of the opinion that there's no point using Struts tags when the
functionality is encompassed by a wider standard, for several reasons.
Oooooh, you were right, it IS hard not to say anything!
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problems with Iterator tag Please Help
Posted by Murray Collingwood <mu...@focus-computing.com.au>.
Sometime it's just hard not to say anything. There are lots of different options for
making this work and you don't have to change to JSTL to do it. The logic:iterate tag is
absolutely fine, you just have to get the right parameter names.
Thanksfully there is a pattern to how the parameters of the logic:iterate tag work, and
it's brilliant news that they conform to the other Struts tag libraries. The absolutely
fantastic news is that there is documentation at:
http://struts.apache.org/struts-doc-1.2.7/userGuide/struts-logic.html#iterate
Your code should look like:
<logic:present name="rows" scope="session">
<logic:iterate name="rows" scope="session" id="row">
Hi
</logic:iterate>
</logic:present>
You'll notice how the same parameter names are used on the logic:present as the
logic:iterate, means you only have to learn how to use a parameter once and can then
assume it is used the same way on the other tags.
HTH
Kind regards
mc
On 20 Oct 2005 at 12:48, Dave Newton wrote:
> Troy Bull wrote:
>
> > I have a situation here. I have an ArrayList of DTO objects in session.
> >
> > <%
> > ArrayList rows = (ArrayList) session.getAttribute("rows");
> > if (rows != null) {
> > Iterator i = rows.iterator();
> > while (i.hasNext())
> > {
> > NibuSrchVLocalDTO debug = (NibuSrchVLocalDTO)i.next();
> > out.println("Name: " + debug.getFullName() + "<BR>");
> > }
> > }
> > %>
> >
> > This code here (scriptlet above this line) works perfectly but
> >
> > <logic:present name="rows" scope="session">
> > <logic:iterate id="row" scope="session"
> > collection="rows">Hi</logic:iterate>
> > </logic:present>
>
> 1) Use JSTL.
> 2) The logic tag doesn't automagically grab stuff from scopes like JSTL
> does.
> 3) So, if you're dead-set on not using JSTL, either:
> a) Use the EL version of the struts lib (or if you're on a JSP 2.0
> server) and say collection="${rows}"
> b) Do that bean definition stuff (sorry, don't have time to provide
> reference right now)
>
> I'd go for the JSTL, though.
>
> Hmm, I'm looking at this and being deep in a Lisp project right now I
> might be remembering COMPLETELY incorrectly, so hopefully somebody more
> awake and smart will jump in. Sorry.
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.12.4/143 - Release Date: 19/10/2005
>
FOCUS Computing
Mob: 0415 24 26 24
murray@focus-computing.com.au
http://www.focus-computing.com.au
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.12.4/143 - Release Date: 19/10/2005
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problems with Iterator tag Please Help
Posted by Dave Newton <ne...@pingsite.com>.
Troy Bull wrote:
> I have a situation here. I have an ArrayList of DTO objects in session.
>
> <%
> ArrayList rows = (ArrayList) session.getAttribute("rows");
> if (rows != null) {
> Iterator i = rows.iterator();
> while (i.hasNext())
> {
> NibuSrchVLocalDTO debug = (NibuSrchVLocalDTO)i.next();
> out.println("Name: " + debug.getFullName() + "<BR>");
> }
> }
> %>
>
> This code here (scriptlet above this line) works perfectly but
>
> <logic:present name="rows" scope="session">
> <logic:iterate id="row" scope="session"
> collection="rows">Hi</logic:iterate>
> </logic:present>
1) Use JSTL.
2) The logic tag doesn't automagically grab stuff from scopes like JSTL
does.
3) So, if you're dead-set on not using JSTL, either:
a) Use the EL version of the struts lib (or if you're on a JSP 2.0
server) and say collection="${rows}"
b) Do that bean definition stuff (sorry, don't have time to provide
reference right now)
I'd go for the JSTL, though.
Hmm, I'm looking at this and being deep in a Lisp project right now I
might be remembering COMPLETELY incorrectly, so hopefully somebody more
awake and smart will jump in. Sorry.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problems with Iterator tag Please Help
Posted by ra...@tcs.com.
Use the following code....
<logic:present name="rows" scope="session">
<logic:iterate id="row" name="rows" scope="session"
type="NibuSrchVLocalDTO"> Hi </logic:iterate>
</logic:present>
This will print the "Hi" the number of times depending on the size of
ArrayList. Also do not forget to use the fully qualified name with package
for type="NibuSrchVLocalDTO"
Regards,
Rajasekhar Cherukuri
Troy Bull <tr...@uni.edu>
10/20/2005 08:56 PM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
Struts Users Mailing List <us...@struts.apache.org>
cc
Subject
Problems with Iterator tag Please Help
Hello
I have a situation here. I have an ArrayList of DTO objects in session.
<%
ArrayList rows = (ArrayList) session.getAttribute("rows");
if (rows != null) {
Iterator i = rows.iterator();
while (i.hasNext())
{
NibuSrchVLocalDTO debug = (NibuSrchVLocalDTO)i.next();
out.println("Name: " + debug.getFullName() + "<BR>");
}
}
%>
This code here (scriptlet above this line) works perfectly but
<logic:present name="rows" scope="session">
<logic:iterate id="row" scope="session"
collection="rows">Hi</logic:iterate>
</logic:present>
this code here with teh iterate tag does not it gives me the following
error:
javax.servlet.jsp.JspException: Cannot create iterator for this collection
at
org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:310)
at _search._jspService(search.jsp:96)
[/search.jsp]
I have these 2 code fragments in the same JSP right next to each other,
I tested by removing one fragment at a time. Any pointers would be
greatly appreciated.
thanks in advance
troy
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
ForwardSourceID:NT00006592
Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you