• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

useBean/getProperty mystery

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic