Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

useBean/getProperty mystery

 
Marcellus Tryk
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marcellus Tryk
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops - did I say page 320? I meant 302. Sorry! It's the 2nd edition and the code is del_menu.jsp.
Thanks,
Mars
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic