File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Simple Bean question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Simple Bean question" Watch "Simple Bean question" New topic
Author

Simple Bean question

Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Hello all,
I have a very simple question, but I can't figure it out:
How do get this to work (partially pseudo code):


The problem is that I want to use the getProperty to display to display the price of the item, but I get the error :

Thanks for your help!

Erik
[ January 27, 2003: Message edited by: Erik Pragt ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8845

Just check whether u have stored it properly in session scope.


Groovy
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
well, actually, the Vector is in the session. When I use

instead of

it does work..
isuraeru
Greenhorn

Joined: Jan 28, 2003
Posts: 7
Originally posted by Erik Pragt:
well, actually, the Vector is in the session. When I use

instead of

it does work..

You can use:
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Hi Erik
Yup, first declare the bean using <jsp:useBean> before using the <jsp:getProperty> and <jsp:setProperty> functions.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1863
hi Erik
consider these two points,
1. in the first post you provided, you have object "items" in the session which is Vector and not a bean.
2. when you do getProperty then it looks for a bean in page, request, session, application scopes (well this sequence of lookup would be altogether another discussion i would say) and tries to do getAttribute("beanname") from them. if it does find it then tries to get the property you specified.

given these two points, we can easily see that when you tried to do getProperty on the "item" bean it looked for that in page,request,sesssion,application scopes where it didn't find it as you have a Vector of "items" in the session (not the bean), right?
doesn't matter that you did use the for loop. it doesn't change the fact that we don't have the appropriate bean object in the session.
so that approach obviously doesnt work.
as you have Vector of Beans in the session and you want to use each of those bean object separately to getProperty, it won't help you to use useBean tag either...how will it help??
the only way is to ignore use of getProperty tag and use


item.getPrice();


that you suggested in your second post....that is the only way you would get this working....
you can't put objects of beans with the same name in the session....
hope this helps.
regards
maulin.


1. Have fun @ http://faq.javaranch.com/java/JavaRaq
2. Looking for simple infix2postfix conversion and postfix evaluation package? Click here
Howard Ralston
Ranch Hand

Joined: Jun 25, 2001
Posts: 105
Hi Erik,
Is it possible you spelled the word "property" wrong in your code as you did in your sample?
<jsp:getProperty name="item" propery="price" />


<a href="http://www.getlocaldeals.com" target="_blank" rel="nofollow">Free local coupons</a>
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Hello everyone, sorry about the typos, the most useful answer came from Maulin. I figured that it wouldn't be possible to do it the way I wanted to do it, but you clearly explained why I was wrong.
My thanks for that, you were a big help. Everyone else: thanks for your response, I also really appriciate that!
Greetings,
Erik
 
 
subject: Simple Bean question
 
Threads others viewed
Sorry For Throwing Lengthy Codes At This Site, But I Really Need Help
Syntax
How to use array of beans in jsp
How to retrieve a Vector of beans without using taglib ?
javax.servlet.ServletException: Cannot create bean of class...
Two Laptop Bag