Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to use beans in jstl  RSS feed

 
nizams uddin
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>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's the problem?
 
Stefan Evans
Bartender
Posts: 1836
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
 
Christophe Verré
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().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!