Forums Register Login

how to use beans in jstl

+Pie Number of slices to send: Send
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">
<c:out value="${emp}" />
</c:forEach>
+Pie Number of slices to send: Send
So what's the problem?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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().
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1408 times.
Similar Threads
taglib descriptor
Default JSTL URI can't be resolved
can i call a function of servlet using jstl
Using JSTL forEach with a custom tag
Mixing JSF and JSTL
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:17:27.