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
The tab creates a variable with the name ItemListVec. I don't know hoe you could retrive the elements of the vector with getProperty.
Joined: Nov 27, 2001
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
Joined: Nov 22, 2008
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.
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