• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why no dynamic values for jsp:useBean  RSS feed

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!