This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean type requirements

 
Ken Duncan
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ, the statement is made that in the jsp:useBean tag, if you only specify the type and not the class, the bean must exist as an attribute and already be in the defined scope. e.g., page scope. I have a question about this. If the bean object is set as an attribute in the request, that's fine, but if I specify a scope of page or specify no scope at all, which equals page, since the jsp:useBean tag typically comes at the beginning of the JSP, the bean is not, I would think, in page scope yet because the request object has not been processed by the JSP (except perhaps under the covers). So will it ever work to specify type and not class for a bean that exists as a request attribute if not scope is specified? Thanks.

Ken
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terrific observation!

I don't think it's common in the real world to use type without class. In fact, I'm straining my brain to think if I've ever used jsp:useBean.

There might be some scenarios where the file containing jsp:useBean might make sense to expect a page scoped bean if you knew the JSP was never used independently, meaning you know it is always used via include. I seriously doubt if I'd write something like that, but still.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Duncan

Do you mean : if you use jsp:useBean without to specify a scope - then the bean in in the page scope, that means before the jsp:useBean you must add the bean in to the scope.
If this is what you mean you are right you must register the bean before usage.
There is one scenario when you don't need to do this - on static include
(@include file =".."), in this case the included file is just copied (inserted) on a certain position in your jsp, and this position can be after the point where you register the bean (in the page scope).

Regards
M
 
Rakesh Vende
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Mr. Duncan

It wont work ever. If your question is something like that

<% jsp:useBean id="somename" type="sometype" %> definalty container will look for existing bean instance in the PAGE SCOPE only not in request scope.

Hence in this case keepig bean instance in request will never server a purpose.

Regards,
Rakesh Vende
(SCJP)
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there's any problem here, and I think you're saying two different things, but I may be missing something. If the bean is not in the session, you should not use useBean with a session scope and only a type. Same for the page scope. If the bean is not in the page, you should not use useBean with a page scope and only a type. Same problem, with a different scope.

You have some chances to put the bean in the session before forwarding to the page. Same for the page scope. You're still allowed to make the bean before the useBean tag. But using what ? A scriplet ? That would be meaningless.

So will it ever work to specify type and not class for a bean that exists as a request attribute if not scope is specified?

As a request attribute ? That's a different question, isn't it ? If you don't set the scope, useBean will look into the page scope. If the bean is in the request, it will fail. (same comment as Rakesh)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic