Matt,

My implementation is pretty domain specific though (our image tag requires a
parent tag to set up some context), so my actual code is not generalizable,
but here's the essence of it (cutting and pasting, and trimming down to the
essentials):

import org.apache.struts.taglib.html.ImgTag;
public class ImageImgTag extends ImgTag {

    protected String src() throws JspException {

        String path = lookupPath(pageContext.getRequest(), src);

        return path;
    }
}

The implementation of lookupPath is, of course, left as an exercise to the
reader, but in our case it looks up a URI (or URL fragment) from a
properties file, and using java.text.MessageFormat replaces the appropriate
pieces in that string and returns it.   The reason the request is passed in
is so that the URL can be relatively specified to the app. context(i.e.
prefixed with request.getContextPath()) or absolutely specified (depending
on whether it starts with a forward-slash or not.   In our case we aren't
using the ImgTag provided "src" variable, I just faked that for the above
example, but that would be one way to pass in the image filename (with no
path, I presume) and have that appended to a looked-up URL prefix.   We use
this feature to serve images from our application server (which gets them
from the DB as BLOB's) or from statically generated files using Apache
directly, and at configuration time we can specify where images get served
from.

    Erik

----- Original Message -----
From: "Matt Raible" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 06, 2001 1:56 PM
Subject: Re: bean:define, bean:write


> Would you mind sharing this?
>
> --- Erik Hatcher <[EMAIL PROTECTED]> wrote:
> > My approach to externalizing image paths was to extend
> > org.apache.struts.taglib.html.ImgTag and use a custom tag to define
image
> > URL's using the existing pieces ImgTag provides.   Overriding src() is
used
> > to look up the look up the image URL base path from a properties file.
> >
> > I've similarly created a custom tag that outputs the image URL as a
string,
> > so that it can be used in JavaScript or in other ways if necessary, and
it
> > relies on a common utility method to retrieve the image URL path that is
> > shared with the ImgTag subclassed tag.
> >
> >     Erik
> >
> >
> > ----- Original Message -----
> > From: "Matt Raible" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, September 06, 2001 12:33 PM
> > Subject: Re: bean:define, bean:write
> >
> >
> > > I don't think there's such a thing as <jsp:define> is there?
> > >
> > > I have a similar question - I'd like to use <bean:define> at the top
of my
> > > page, but it is not used if one already exists...
> > >
> > > What I'm trying to do is set a path to all my images that lives on the
> > > webserver.  I'd like to externalize this value into the web.xml - is
this
> > > possible.  If so, how do I retrieve it in my page.
> > >
> > > Currently, I'm doing this:
> > >
> > > <%
> > > String imagePath = "/blah/image";
> > > %>
> > > image path is <%=imagePath%>
> > >
> > > I was thinking of using bean:define to get rid of the scriptlet, but
now
> > I'm
> > > thinking it would be better to put in a config file.
> > >
> > > Also, I've used my ApplicationResource.properties as a place to store
> > default
> > > values for populating a form - does anyone recommend a better way?
> > >
> > > Thanks,
> > >
> > > Matt
> > > --- Keith Bacon <[EMAIL PROTECTED]> wrote:
> > > > My guess is that jsp:define creates it if not there
> > > > but struts bean:define doesn't.
> > > >
> > > >
> > > > --- David Corbin <[EMAIL PROTECTED]> wrote:
> > > > > I thought that bean:define takes care of that....
> > > > > ----- Original Message -----
> > > > > From: "Keith Bacon" <[EMAIL PROTECTED]>
> > > > > To: <[EMAIL PROTECTED]>
> > > > > Sent: Thursday, September 06, 2001 11:18 AM
> > > > > Subject: Re: bean:define, bean:write
> > > > >
> > > > >
> > > > > > Is it because you haven't done a
> > > > > >
> > > > > > request.putAttribute("pageTitle", yourObject);
> > > > > >
> > > > > > in your ActionForm?
> > > > > >
> > > > > > Keith.
> > > > > >
> > > > > >
> > > > > > --- David Corbin <[EMAIL PROTECTED]> wrote:
> > > > > > > Why does this jsp fragment generate an exception
> > > > > > >
> > > > > > > javax.servlet.jsp.JspException: Cannot find bean pageTitle in
> > > > > scope
> > > > > > > request
> > > > > > >
> > > > > > > --cut--
> > > > > > > <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> > > > > > > <bean:define id="pageTitle" value="foobar" scope="request"/>
> > > > > > >
> > > > > > > <HTML>
> > > > > > >     <HEAD>
> > > > > > >          <TITLE><bean:write name="pageTitle"
> > > > > > > scope="request"/></TITLE>
> > > > > > >     </HEAD>
> > > > > > > . . .
> > > > > > >
> > > > > > > --cut--
> > > > > > >
> > > > > > > Thanks
> > > > > > > David Corbin
> > > > > > >
> > > > > >
> > > > > >
> > > > > > __________________________________________________
> > > > > > Do You Yahoo!?
> > > > > > Get email alerts & NEW webcam video instant messaging with
Yahoo!
> > > > > Messenger
> > > > > > http://im.yahoo.com
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > > __________________________________________________
> > > > Do You Yahoo!?
> > > > Get email alerts & NEW webcam video instant messaging with Yahoo!
> > Messenger
> > > > http://im.yahoo.com
> > >
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Get email alerts & NEW webcam video instant messaging with Yahoo!
> > Messenger
> > > http://im.yahoo.com
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email alerts & NEW webcam video instant messaging with Yahoo!
Messenger
> http://im.yahoo.com

Reply via email to