• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to retrieve a Vector of beans without using taglib ?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have a "MyServlet.java", "My.jsp" and "ItemList.java" which is a bean class. First "MyServlet.java" handles some business logic and then feeds a Vector of items into "ItemList" bean and creates a vector of Litemlist bean, then do
request.setAttribute("ItemListVec", v);
and forward(request, response) to "My.jsp".
Question is-- In "My.jsp", if I don't use taglib, and just want to use <jsp:useBean> <jsp:getProperty> syntax, how can I retrieve the ItemList vector ? The "id" in jsp:useBean is associated with the vector, not element, and this "id" matches to "ItemListVec". How do I get info. from each element ? what "id" should I use when I retrive element ?
I know I can do in a similar way by simply do:
request.getAttribute("ItemListVec");
then loop through it and get the info from each element. But in this way, I am NOT using <jsp:useBean> <jsp:getProperty> syntax, am I still using MVC ?
thanks,
Ian
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is very simple,

The tab creates a variable with the name ItemListVec. I don't know hoe you could retrive the elements of the vector with getProperty.
 
Ian Yang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this. but my question is :
your "id" here refers to a vector instead of a bean class instance. how to retrive the elements is my problem.
Ian
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I no have idea how to retrieve the elements with getProperty.
The answer to the other question is yes although you use java code in <%%> form you are still in the MVC model if the <%%> in JSP is regarding to presentation.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just don't use the getProperty tag. Put standard Java code to get the values out of the vector elements in a scriptlet.
Kyle
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ian,
Yes, you are still using a version of MVC. The main point is you've identified a workable pattern. I use the same thing. Just because you're not using JSP's methods for accessing a bean doesn't mean you've broken the pattern. Patterns are, and should be, as independent from implementation as possible.
Actually, my first run at using JSPs I just posted to a servlet, called a domain model class to get my database results back as a collection, then set the attribute into the request and forwarded to the JSP for display. In the JSP I just pulled an Enumeration out of the Vector and and looped through to get my results. My Vector was actually of Hashtable items, each one representing a row of the resultset. Here's a sample:

My next run at doing this will be to see if using JavaBeans in the Vector (or ArrayList?) would be worthwhile, or limit flexibility. I have the luxury of our dept. not having any HTML 'artistes' who do not program, so this pattern works great for us.
Something you might look up Service-To-Worker at the Sun Java Center for another example. There's other patterns there that are useful as well, and like the one I stumbled upon and you did, too, patterns that aren't necessarily documented but are simple and useful.
Hope this helps!
 
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic