Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Binding scriptlet variable with jsp:useBean

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic