Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Binding scriptlet variable with jsp:useBean  RSS feed

 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

currently I maintain a project which makes heavy(!) use of scriptlets in its JSPs. There is one things that bugs me most. Each pages includes a default.jsp, this default JSP contains a scriptlet that creates a Context object ctx which offers access to the user, his roles etc. In the specific pages this often results in something like:


The example above checks whether to show a button for a delete action, depending on a user's role. This will get nasty if more roles are added or something the like.

Now I'd like to replace the scriptlets that use ctx objects with a ctx bean, for example (note: note the scriptlets in the default.jsp, only on some JSP that include the default.jsp). I tried to create a bean after the Context is created in the default.jsp like this:



but this bean is not created out of the original "scriptlet ctx", it is a completely new bean instead. What am I missing?
[ January 30, 2008: Message edited by: Mike Himstead ]
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr Mike, your question is not quite clear. If you want to replace that default.jsp having the scriptlets, with a bean, then write a java class which accomplishes the same functionality as the scriptlets. Also in the <jsp:useBean >tag you have not mentioned the 'class' attribute.
 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, I corrected the missing class attribute from above.

I'll try to explain what I'd like to achieve:
I don't want to use scriptlets that use the ctx Context object which is created in the included default.jsp. This would increase spreading scriptlets on all current and new JSPs. I'd like to access the Context by a tag. While I can change the default.jsp, I can't change the Context class / source per se since it belongs to a basic module which is used by other applications as well (they all use the same approach).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the name ctx already exists in session scope the <jsp:useBean> action will just hook up to it. So, is the object already bound to session scope?
 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, apparently not since jsp:useBean doesn't hook up to the previously created ctx object; I didn't put the object into the session. Mmh, I will have to think it over if it makes sense to do so (I don't want to create any security leaks or unwanted side-effects).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's back up a little. What exactly are you trying to achieve?

Let's review:

1) The default.jsp file is included on every JSP. (Statically, I assume? If so, it should be named default.jspf.) This establishes a scripting variable named ctx on each page that contains information that needs to be referenced in order to do stuff.

2) You want to avoid having to use scriplets to reference ctx. How? Saying "I want to use beans" doesn't tell us anything. Be specific. Are you wanting to use JSTL/EL? Write your own custom tags? All of the above?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!