aspose file tools*
The moose likes JSP and the fly likes How to retrieve a Vector of beans without using taglib ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to retrieve a Vector of beans without using taglib ?" Watch "How to retrieve a Vector of beans without using taglib ?" New topic
Author

How to retrieve a Vector of beans without using taglib ?

Ian Yang
Ranch Hand

Joined: Nov 27, 2001
Posts: 44
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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 27, 2001
Posts: 44
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

Joined: Nov 22, 2008
Posts: 18944
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.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
Just don't use the getProperty tag. Put standard Java code to get the values out of the vector elements in a scriptlet.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
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!


CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)
Author of Posts in the Saloon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve a Vector of beans without using taglib ?
 
Similar Threads
How to retrieve a Vector of beans without using taglib ?
unable to pass value of resultset to servlet to jsp
usebean getProperty and setProperty in the same form field
HELP! JSP doesn't SAVE VALUES to BEAN
how to properly catch/display exception in jsp ?