Erik Beijnoff wrote:
If a tag needs to build an object structure based on an initialization
file, what's the best way to do it?

The BodyTag interface does not seem to have any sort of initialization
that's done onload, like Servlets and Filters. What's the reason for
this? Are they not meant to be used this way?

Unique tag handler instances are created for different occurances of the corresponding custom actions, so initialization in the same way as for servlets and filters would not be efficient (there's only one instance of a servlet or filter).

The alternatives I'm facing are:
1. Write some sort of separate initialization procedure to read in the
initialization file on web server start up. Then send the created object
structure that reflects the initialization file as a parameter to the
tag.

I recommend a variation of this. Write a context lifecycle event listener that creates the structure from the file on startup. Save a reference to the structure as a context attribute, and let the tag handler get it in the doStartTag() method:

  MyStructure ms = pageContext.getAttribute("myStruct",
    PageContext.APPLICATION_SCOPE);

2. Use another approach, since the tags architecture does not seem to be
created for config initialization. For example trying to use a filter
for the task instead.

A filter gets invoked on each request, so unless you need to read the file on each request (e.g., to get the latest data), the above is more efficient.

Hans
--
Hans Bergsten                                <[EMAIL PROTECTED]>
Gefion Software                       <http://www.gefionsoftware.com/>
Author of O'Reilly's "JavaServer Pages", covering JSP 1.2 and JSTL 1.0
Details at                                    <http://TheJSPBook.com/>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com

Reply via email to