Re: [Help] Struts/JSP -- easy way associate an "ID" to a "Value"?
From: Java Architect (danc_at_dynamicresolve.com)
Date: 07/07/04
- Next message: vishnu mahendra: "Is applets are Interpreted programs?"
- Previous message: jack: "Re: RS232 data to Access database - general approach"
- In reply to: Russ Perry Jr: "Re: [Help] Struts/JSP -- easy way associate an "ID" to a "Value"?"
- Next in thread: Russ Perry Jr: "Re: [Help] Struts/JSP -- easy way associate an "ID" to a "Value"?"
- Reply: Russ Perry Jr: "Re: [Help] Struts/JSP -- easy way associate an "ID" to a "Value"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 7 Jul 2004 14:34:16 -0700
Putting this kind of data in session scope is a bad idea. The id->value
mapping shouldn't be changing across the lifetime of the app (or else you're
going to end up with data integrity problems), so why keep it in session as
opposed to application (servlet context) scope?
Better yet, you should have a DAO that can keep these in a cache so that, in
your action, you ask for the map and then set it as an attribute of the
request. What does this get you? Well, your DAO is responsible for managing
the cache and your app doesn't have to worry about where the data is stored
(in the DB or in memory). Putting it on the request makes it immediately
available to your your view controller, your JSP, and any tiles without them
having to know anything about the DAO. This layers your app nicely.
"Russ Perry Jr" <slapdash@rcn.com> wrote in message
news:c630de0a.0407070818.7bede4a7@posting.google.com...
> "Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote:
> > "Russ Perry Jr" <slapdash@rcn.com> wrote:
> >> I think I've found more "trouble" with the Map... I can make a Map
with
> >> the ID/value pairs no sweat. Now, how do I reference them on the JSP?
>
> > Assume you have something beanish like this:
> > public class SomeBean {
> > Map values = new HashMap();
> [...]
>
> Actually, not quite... Right now we just make the Map in an init servlet
> and throw it into session scope.
>
> > In the JSP, using JSTL, do this:
> [...]
> > According to Struts documentation, you should use JSTL over Struts tags
> > whenever possible. See above :)
>
> Ah... Right now, we're not using JSTL. It was hard enough trying to
> convince people around here that we should be using JSP tags instead
> of embedded Java. So, I might look into it, but I probably won't be
> able to get permission to use it in our app, at least not version 1.0.
>
> >> The other issue is that I'm not sure how to get the common info Map
from
> >> ServletContext while in my ActionForm (as shown on that same page) to
have
> >> the Map to do the get() on...
>
> > Why would you need anything from a ServletContext in an ActionForm?
>
> Turns out I don't. It's just the way I was looking at it at first; the
> most direct route was to put a getValueField() method in the ActionForm
> to pull the info out of the Map, which I needed to retrieve from session
> scope, which would have required the ServletContext.
>
> > ActionForms are strictly for modeling HTML forms and getting the
information
> > from the user to your Action.
>
> Just an aside, I'm new to Struts (obviously), so it's hard for me to tell
> when I'm being clever, when I'm reinventing the wheel, and when I'm doing
> something "bad". I'm not in a position where I can justify reading a lot
> at work, nor do I have much time to do so at home either.
>
> > In an Action, you have access to (most likely) an HttpServletRequest
> > object named "request". To get a ServletContext from there:
> > request.getSession().getServletContext()
>
> Yeah, that part's easy. We're doing that kind of thing all over, no
> problems.
>
> What I ended up doing, at least for the time being, is to get() the info
> from the Map in my Action, but also setting up a simple bean with it to
> use on the JSP. It works, though it might not be ideal.
>
> Thing is, at the moment I have two different common objects -- a Vector
> for the initial JSP, and the Map for the confirmation JSP. I've seen
> references that you can't use a Map with a <html:options> tag, but other
> places say it can, so I'll probably try that soon, as I'd like to minimize
> the amount of monkey work I'm doing with the two objects and extra bean,
> etc...
>
> Thanks again for your reply.
- Next message: vishnu mahendra: "Is applets are Interpreted programs?"
- Previous message: jack: "Re: RS232 data to Access database - general approach"
- In reply to: Russ Perry Jr: "Re: [Help] Struts/JSP -- easy way associate an "ID" to a "Value"?"
- Next in thread: Russ Perry Jr: "Re: [Help] Struts/JSP -- easy way associate an "ID" to a "Value"?"
- Reply: Russ Perry Jr: "Re: [Help] Struts/JSP -- easy way associate an "ID" to a "Value"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|