File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes nested logic:iterate tags possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "nested logic:iterate tags possible?" Watch "nested logic:iterate tags possible?" New topic
Author

nested logic:iterate tags possible?

John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
hello all,
i want to check whether a collection in my bean is empty, if not, i want to present a form which contains some text which is extracted from the bean. there are 2 distinct collections, all the elements of which i want to print out like "groupname: jobname" (w/o the quotes).
the following is how i think it should work (but it doesn't...):

any ideas as how i can accomplish this?
thanks!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

As you have seen, you can't process two collections in parallel using nested iterate tags.
You'll just have to put whatever you want to display into a single collection and iterate over it.
Alternatively, you could use a scriptlet to do it but you might be trying to avoid scriptlets. Anyway, here's a scriptlet (NOTE: untested but it works in my head <grin>)

Note the use of "&" instead of "&&" to force the full evaluation of the loop condition. This ensures that the loop will exit when one of the iterators runs out of elements.


Junilu - [How to Ask Questions] [How to Answer Questions]
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
ok, it seems like either way i do it, for some reason the jsp page actually stops loading mid-page and i get a white screen. currently, i'm trying this:

the batchGroup object is declared at the top of the page like: <jsp:useBean id="batchGroup" scope="session" class="com.xxx.xxx.BatchGroup" />.
the batchGroup object is initially instantiated in an initializer servlet which sets the object to the session (session.setAttribute("batchGroup", batchGroup). in the jsp page to which control is redirected by the init servlet, i refer to the declared jsp bean within my scriptlets without getting the attribute from the session (i am assuming that the jsp:useBean declaration takes care of that).
if i remove the "<logic>" tag code, all looks fine, until the batch group size is larger than 0. then i get the white page. if i remove the code altogether, the page loads fine (albeit w/o what i'm trying to accomplish with the logic tags).
any ideas why it's crashing?
thanks!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

In the BatchGroup class, is the getter for the size property called getSize() or simply size()? The tag needs it to be getSize().
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
you are correct--the getter is called getSize(). i changed the property to getSize() but now i get the white screen regardless of the size of the batch group... i've tried the "present/notPresent, empty/notEmpty" tags also, but they result in the same partial page too.
very confused...
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

View the source of the generated html and see if there are any hidden stack traces. If there are, post a the first 10 or 20 lines.
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
that's the bizarre thing--there is no stack trace, just the html page partly generated... (it's just the page it's supposed to display, stopped in the middle of my javascript function--it has nothing to do with the actual javascript function though, since removal of the offending "logic" code allows normal loading of the entire page). i am pretty sure that the problem has to do with the opening logic tag, but don't know what is wrong...
on a side note, is it ok to get/set session attributes from the Action servlet which are used globally in the app?
let me know if there's any other code you'd like to see.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

What environment are you developing in? Can you debug/step through the execution and place a breakpoint in the BatchGroup.getJobs() method? Can you debug/step through your JSP?
Did you try the scriptlet that I gave before or some slight variation of it? I don't know if it has anything to do with the problem but personally, a TreeMap wouldn't be my first choice to hold the list; I would have used an array or ArrayList.
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
owing to a number of stupid errors on my part(like forgetting about the html:form tag...) things now work. i've used a variation of your scriptlet (w/o the original idea of looping through 2 collections) and everything is just peachy.
thanks for all your help!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Originally posted by John Low:
owing to a number of stupid errors on my part(like forgetting about the html:form tag...) things now work.

Bad Greenhorn! I should've known better...
Now go out to corral and gather up two big piles of cowchips.
I'm glad you worked things out though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested logic:iterate tags possible?