GeeCON Prague 2014*
The moose likes JSP and the fly likes How to iterate over all attributes with pure tags and EL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "How to iterate over all attributes with pure tags and EL?" Watch "How to iterate over all attributes with pure tags and EL?" New topic
Author

How to iterate over all attributes with pure tags and EL?

r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Hi,

is it possible to iterate over all pagecontext-attributes using pure taglibs & el?

Like:



If I try this I get the error: Cannot find bean org.apache.catalina.core.ApplicationHttpRequest$AttributeNamesEnumerator@9daa17 in any scope
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
I'd go with the JSTL loop rather than the struts loop.
Struts actually deprecated their loop tag in favour of the JSTL one.
Struts and JSTL tags work together without a problem.

EL also makes available some implicit variables: pageScope, requestScope, sessionScope, applicationScope which are maps of the attributes in each scope.
That is easier than using the methods on the request object.

Here is a JSP snippet that will print out all the variables in page scope plus their value
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Thanks. Any tricks available to iterate over the different scopes (page, request, appl, session) via jslt?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

Is that not what Tim just gave you the code for?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
No, this iterates over the attributes in 1 (!) scope. What I mean is something like this:



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

There is no Map that aggregates all the scopes. You need to iterate over each scope individually.
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Ok, thanks.
 
GeeCON Prague 2014
 
subject: How to iterate over all attributes with pure tags and EL?