Thanks to everyone for the replies.  I'm thinking that my best approach (as
yet untested) will probably be to combine string parameter passing (using
jsp:param) and request attributes: i.e. use string parameters to identify
the name of the request attribute, and an object in that request attribute
to store my actual data.  That way I can keep the namespaces of each file
completely separated but still refer to objects between them.
e.g.
<jsp:useBean id="tab1" class="com.foo.MyTab" scope="request">
        <%-- set parameters --%>
</jsp:useBean>
<jsp:useBean id="tab2" class="com.foo.MyTab" scope="request">
        <%-- set parameters --%>
</jsp:useBean>
<jsp:include page="tab.jsp">
        <jsp:param name="tab" value="tab1" />
        <jsp:param name="tab" value="tab2" />
</jsp:include>

Now I just have to work out how well it handles sending multiple values in
like that, and see if maybe I need to just use one and wrap it up in a
Vector or whatever.  Anyway, thanks again.

Cheers,

Chris

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Chen, Gin
Sent: Friday, November 09, 2001 11:19 AM
To: [EMAIL PROTECTED]
Subject: Re: Passing parameters to includes


Chris,
        Depending on how dynamic you want the text to be there are several
methods you can use. For example. if a specific include page has a button
with the text "hello" and that changes only when business requirements
dictate it. You can actually just put it into your web.xml file as an init
parameter. You see this alot with webaddresses. For example a JSP page that
is included as a footer file may have a "Questions and Comments contact the
webmaster" where the webmaster is actually a link that says
<.mailto:[EMAIL PROTECTED]> (the . was put to prevent this from showing in
HTML) That web address is usually placed as a web.xml init param called
webmaster (or whatever).
        But if the text must change dynamically depending on who is
accessing the page. It may be better to have it as a database value stored
and keyed by the customers id.
        Another approach is just do it the way that you are now. But that
may cause a problem as the url has a length limitation and depending on how
many fields you are setting this may cause some problems. Security is of
course an issue with that method as well. Any user can tell that you are
setting up fields through the URL and can easily just pass a new URL to
display what he/she wants to display.
        Of course there are more solutions as well but I think these 2 are
the main solutions if you are not hardcoding values.
-Tim

-----Original Message-----
From: Chris Tucker [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 09, 2001 2:14 PM
To: [EMAIL PROTECTED]
Subject: Passing parameters to includes


Hi all,

I was wondering how other people approach the problem of passing parameters
to include files (or even if this is really something that it's a good idea
to do...).  For example, say I want to specify some button text for an
included file, I may want pass a parameter called "buttontext" with the
value "Hello".  The way I've been approaching this so far is to encode the
parameters as a query string on the include URL, e.g.
<jsp:include page="test.jsp?buttontext=Hello" />
but this doesn't really scale up to anything more than simple textual
arguments.  I could add stuff to the session or context, allowing me to use
more complex objects, but I don't want to be creating a load of
interdependencies as far as attribute naming etc. is concerned between an
include file and the file including it.  Ideally, I'd like to just be able
to parameterise the include as one would a method.

Any suggestions?

Chris Tucker

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to