• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

how to use beans in jstl  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to use a bean in jstl

in my servlet i set
session.setAttribute(SDFISearchResponseVO.class.getName(),sdfiSearchResponseVO);

now in my jsp i need to use this.
this bean has methods such as getA() , getB();
whose return type is arraylist.

i want to use something similar to <c:forEach items="${SDFISearchResponseVO.a}" var="emp">
<cut value="${emp}" />
</c:forEach>
 
Author and ninkuma
Marshal
Posts: 66806
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's the problem?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem I can see is the name the attribute gets set under: SDFISearchResponseVO.class.getName()
Presuming this is in a package, the attribute would be stored in session under the name "com.package.SDFISearchResponseVO"

Long and unwieldy to say the least. Also accessing names with dots in them isn't so straight-forward.
It would probably have to be something like

<c:forEach items="${sessionScope['com.package.SDFISearchResponseVO'].a}" var="emp">


I would probably cheat with a <c:set> tag at the top of the page:
<c:set var="SDFISearchResponseVO" value="${sessionScope['com.package.SDFISearchResponseVO']"/>
The forEach should then work.

Cheers,
evnafets
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would set a fix name to map the bean. If the class is refactored, all JSPs referring to it will also need to be updated. I don't think it's such a good idea to use SDFISearchResponseVO.class.getName().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!