array arguments to jsp taglibs

R

Roedy Green

I have been working on how I to translate my static macro scheme to
JSP taglibs. I have not yet figured out how to pass an array argument
or a variable number of arguments to a JSP tag. Is it possible?
--
Roedy Green Canadian Mind Products
http://mindprod.com

"I mean, source code in files; how quaint, how seventies!"
~ Kent Beck (born: 1961 age: 48), evangelist for extreme programming.
 
D

Donkey Hottie

Roedy Green said:
I have been working on how I to translate my static macro
scheme to JSP taglibs. I have not yet figured out how to
pass an array argument or a variable number of arguments
to a JSP tag. Is it possible?

Most jsp tags do have variable number or arguments.

<bean.define id="first" name="first" />
<bean.define id="first" name="first" type="java.lang.Integer" />
 
R

Roedy Green

Most jsp tags do have variable number or arguments.

<bean.define id="first" name="first" />
<bean.define id="first" name="first" type="java.lang.Integer" />

tags have optional arguments.

I am looking for something like:

<mytag:lines line=["first line", "second line", "third line"]>

or

<mytag:lines line="first line" line="second line" line="third line">
--
Roedy Green Canadian Mind Products
http://mindprod.com

"I mean, source code in files; how quaint, how seventies!"
~ Kent Beck (born: 1961 age: 48), evangelist for extreme programming.
 
D

Donkey Hottie

Roedy Green said:
Most jsp tags do have variable number or arguments.

<bean.define id="first" name="first" />
<bean.define id="first" name="first"
type="java.lang.Integer" />

tags have optional arguments.

I am looking for something like:

<mytag:lines line=["first line", "second line", "third
line"]>

or

<mytag:lines line="first line" line="second line"
line="third line">

Ok.

How about using a Collection as the parameter?
 
R

Roedy Green

How about using a Collection as the parameter?

Sounds promising. What do I write for my tag to create the
Collection? The way I read the docs, parms are always strings, though
they can be computed with EL.


<mytag:lines line="${???}">

Do you mix scriptlets and tags or avoid tags altogether?
--
Roedy Green Canadian Mind Products
http://mindprod.com

"I mean, source code in files; how quaint, how seventies!"
~ Kent Beck (born: 1961 age: 48), evangelist for extreme programming.
 
A

Alessio Stalla

Sounds promising.  What do I write for my tag to create the
Collection? The way I read the docs, parms are always strings, though
they can be computed with EL.

 <mytag:lines line="${???}">

I think a collection cannot be represented literally, but has to be
the result of EL evaluation, i.e., the return value of some method or
the value of some variable. Now IIRC the EL implementation is
pluggable in recent JSP versions, so theoretically you could build
your own EL implementation with syntax for literal collection values,
but imho it's hardly worth the effort.
Do you mix scriptlets and tags or avoid tags altogether?

Tags are usually preferred to scriptlets due to their declarative
nature, however tags cannot[1] do everything scriplets do. Still, I'd
advise you to keep scriplets small and simple, moving complex parts to
utility methods in a class, to avoid cluttering too much the jsp.

hth,
Alessio

[1] cannot as in "cannot with reasonable effort and ease", not as in
"cannot because it's provably impossible".
 
J

jnizet

Sounds promising.  What do I write for my tag to create the
Collection? The way I read the docs, parms are always strings, though
they can be computed with EL.

 <mytag:lines line="${???}">

The idea of tags is to use data from JavaBeans, which must be present
in one of the scopes (page, request, session or application). You thus
have to put the collection you want to use in your tag in the
appropriate scope, before calling your tag. If you want to pass a
collection of literals directly to your tag, you might use a JSP-EL
function :

<mytag:line lines="${myFunctions:toList('line1', 'line2', 'line3')}"/>

To define a function, see http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html
(end of the page).

I don't know if varargs are supported in EL functions, though. You
might thus have to define one function per number of arguments. Or the
function could parse the string, and transform it into a list :

<mytag:line lines="${myFunctions:toList('line1, line2, line3')}"/>

JB.
 
D

Donkey Hottie

Roedy Green said:
Sounds promising. What do I write for my tag to create
the Collection? The way I read the docs, parms are always
strings, though they can be computed with EL.


<mytag:lines line="${???}">

Do you mix scriptlets and tags or avoid tags altogether?

I don't know, but an old Struts tag logic.iterate takes a collection an
iterates its. Source code is available. The same goes with JSTL forEach.
 
R

Roedy Green

I don't know if varargs are supported in EL functions, though. You
might thus have to define one function per number of arguments. Or the
function could parse the string, and transform it into a list :

<mytag:line lines="${myFunctions:toList('line1, line2, line3')}"/>

“We shall not cease from exploration
And the end of all our exploring
Will be to arrive where we started
And know the place for the first time.”
~ Thomas Stearns Eliot (born: 1888-09-26 died: 1965-01-04 at age: 76)
Four Quartets
--
Roedy Green Canadian Mind Products
http://mindprod.com

"The coolest thing to do with your data will be thought of by someone else."
~ Rufus Pollock (born: 1978 age: 31) in Talk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JDK 1.5.0_21 released 6
InetAddress.isReachable 9
JSP including 12
Daylight saving correction 15
Offsite JSP 18
Basic JSP question 17
writing to DVD 1
bugs.sun.com 11

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top