• 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

Modifying a JSP w/Dynamic

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is kind of a strange one: I have a jsp that currently uses a bean, then proceeds to code the entire bean to do what's needed (which is why I'm asking about the taglib in a previous query). What I need to do is call the bean by a dynamically created name, but be able to reference the dynamic name in the java code.
I've tried passing the value, but it gets treated the same way and has no clue as to what I mean. I'm at a loss. Since I'm pretty certain that something like this will come up again since I'm taking over a whole load of code like this, I'm asking the question now:
<jsp:useBean id="mdTable" class="MDTable" scope="session">
Then, later on,
<%
...
mdTable.setCommandProcessor((com.sas.servlet.util.CommandProcessorInterface)mdcp);
...
%>
What I'm trying to do is:
<jsp:useBean id="<% table %>" class="MDTable"
scope="session" >
Then be able to use the table defined here in the code:
<%
...
%> <% table %> <%.setCommandProcessor((util.CommandProcessorInterface)mdcp);
...
%>
But this isn't working. Any help?
Thanks for your time.
Pat
 
Sheriff
Posts: 67746
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
Given

you should be able to retrieve the bean yourself to use in scriplets:

useBean merely retrieves (or creates, if absent) the specified class from the attribute map of the specified scope.
bear
[ January 07, 2004: Message edited by: Bear Bibeault ]
 
Pat Flickner
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,
Wow, I was thinking this one out way too much. Dead give-away that I'm still green here. Thanks for showing me this one. It's very much appreciated.
Pat
 
Bear Bibeault
Sheriff
Posts: 67746
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
Everyone's green at one time or another. Glad to help!
bear
 
Pat Flickner
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I'm still having problems with this. Let me give the history here:
We have a single set of jsps that is used for all our major apps. All the apps are on the same web server. When an app is used, it uses the same bean with the same bean id (mdTable) scope session. This causes a problem when you bring up more than one app that uses the jsp, because mdTable has already been defined for the session, so it already exists, so there's a problem when the other app tries to bring up its own data using the already-created bean object.
The whole purpose in designing the code this way was to avoid hard-coding as much as possible. Because of the design, once the data are ready on the back-end, including the interface that tells the front-end what to do, the app can be available in less than two minutes by copying two files into a new directory and changing two values on the one file. There is no problem for all of the other because the provided beans are designed in such a way that you can easily use all the same objects and their data do not run over each other.
However, with this one single bean, we have the problem. Can I do something like:
MDTable request.getParameterValues("appTable") = (MDTable)session.getAttribute( table );
That way, I could dynamically create the new object without it running into something else. Otherwise, the only other way would be to create a new file that would be part of the process that would contain the app name.
I'm just trying to figure out how to make this work on a global level. If I can't, then this last option may be just what I need.
Thanks for any help. And Bear, thanks a lot for your input.
Pat
 
Bear Bibeault
Sheriff
Posts: 67746
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
Spot solution: perhaps it would help if you created attribute namespaces for your apps.
In other words, rather than each app storing the attirbute in the session using the name "mdTable", they would qualify it with their own id: "app1.mdTable", "app2.mdTable" and so on. No hard-coding would be necessary since it should be easy to derive a unique namespace prefix for each app from the context path (request.getContextPath()).
However, if this is just one instance of a problem created by sharing resources across your apps, perhaps you should take a step back and figure out a higher-level solution.
bear
 
reply
    Bookmark Topic Watch Topic
  • New Topic