• 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

Why no dynamic values for jsp:useBean

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi geeks,
The id attribute of jsp:useBean accepts only static value i.e. no dynamic value. But surprisingly using servlets it is possible.
I can do
String dynamicKey = "mykey";
session.setAttribute(dynamicKey ,"myvalue");
Dont U think that Sun should also allow for dynamic value for id attribute ?

OR
Could there any reasons for disallowing this?
Eagerly waiting for responses.
Thanks in advance.
 
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
Hi geeks,
The id attribute of jsp:useBean accepts only static value i.e. no dynamic value. But surprisingly using servlets it is possible.
I can do
String dynamicKey = "mykey";
session.setAttribute(dynamicKey ,"myvalue");
Dont U think that Sun should also allow for dynamic value for id attribute ?

OR
Could there any reasons for disallowing this?
Eagerly waiting for responses.
Thanks in advance.


Yes, there are reasons for disallowing it. The code in your servlet isn't quite analogous. Keep in mind that <jsp:useBean> doesn't just create a scoped attribute; it also creates a scripting variable. Scripting variables are part of the code of the servlet that the JSP compiles to; therefore, they must be available at translation time. (Dynamic values, by contrast, are only available at runtime, otherwise known as request time.)
Scripting variables are, in general, somewhat cumbersome; JSTL avoids them.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic