wood burning stoves 2.0*
The moose likes JSP and the fly likes useBean/getProperty mystery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "useBean/getProperty mystery" Watch "useBean/getProperty mystery" New topic
Author

useBean/getProperty mystery

Marcellus Tryk
Ranch Hand

Joined: May 31, 2001
Posts: 64
I have a problem that I find very puzzling. I'm attempting to retrieve an array of objects and then display some member variable values. The relevant code is shown below. The array of job beans are being retrieved successfully, but where I'm attempting to display the values using getProperty I'm only seeing a zero for the numeric variable and blanks for the string variables. If I try to display the values inside the scriptlet with out.println(job.getID()) etc. the values are printed correctly. Any clues?

Thanks Ranchers,
Marcellus A. Tryk
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
When you reassign a scripting variable in a scripting element (that is, a "scriptlet"), the change is not visible to the scoped attribute that is associated with this scripting variable.
If you must modify the value in a scriptlet, then you should display the values with another (or the same) scriptlet. (Don't use out.println(); instead, write <%= job.getID() %> in place of <jsp:getProperty>.)
Alternatively, you could write a custom tag that edits the scoped attribute (or modify the scoped attribute yourself in a scriptlet).
One advantage of using JSTL and "scoped variables" instead of scripting variables is that you avoid the split between variables and attributes, which can clearly be confusing.


Shawn Bayern<br />"JSTL in Action" <a href="http://www.jstlbook.com" target="_blank" rel="nofollow">http://www.jstlbook.com</a>
Marcellus Tryk
Ranch Hand

Joined: May 31, 2001
Posts: 64
Thanks Shawn! The funny thing is that my code is modeled after an example in Web Development with Java Server Pages(Manning Press - Page 320) - which would seem to have the same problem.
Thanks again,
Mars
Marcellus Tryk
Ranch Hand

Joined: May 31, 2001
Posts: 64
Shawn - Duh! I just realized you're one of the authors of the book I cited. That's funny. Well you should be in a good position to tell me why I'm so confused. By the way the book is excellent.
Thanks again,
Mars
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
Ha! I'd be happy to try to compare your code with the example you're reading in Web Development with JavaServer Pages, but I don't see any similar code on page 320 of either the first or second edition. Are you sure you got the page number correct?
[ August 26, 2002: Message edited by: Shawn Bayern ]
Marcellus Tryk
Ranch Hand

Joined: May 31, 2001
Posts: 64
Oops - did I say page 320? I meant 302. Sorry! It's the 2nd edition and the code is del_menu.jsp.
Thanks,
Mars
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: useBean/getProperty mystery
 
Similar Threads
need some help
Servlet - JSP problem
Passing multiple listbox to bean using JSP
JSP Bean error
Servlet - Array of beans error - Help !