tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Benzekri" <s.benze...@PENSON.CA>
Subject RE: [JSTL] Indexed array variable
Date Wed, 02 Jun 2004 15:21:17 GMT
Good idea, I would make the following changes though;

<c:setArray name="myArray" dimension="2" >
  <c:defArray column="Exam1" column="Exam2" column="Avg" row="student">


Which would produce;  

 	       Exam1   Exam2  Avg
  Student1    70	   80      75
  Student2    60     70      65  

To access the individual values I would use something like this;

<c:getArrayValue column="Exam1" row="Student1" /> 
Value fetched would be 80
 <c:getArrayValue column="Avg" row="Student2" /> 
Value fetched would be 65

In the same manner I would use;
<c:setArrayValue column="Avg" row="Student2" value="99" />

This is not perfect but I think it would work; It get's complicated for a 3 dimensionnal array.
 This would mean declaring one of the columns as an array itself....this is a challenge. 



-----Original Message-----
From: Derek Mahar 
Sent: Wednesday, June 02, 2004 10:53 AM
To: Tag Libraries Users List
Subject: RE: [JSTL] Indexed array variable

Good question!  We can represent a multi-dimensional array as a
recursive array of arrays.  For example, given tag <c:setArray>, we
could both allocate and assign a two-dimensional array as follows:

<%-- Create the first row, assign it values at index 0 and 1.
<%-- Assign the row to myArray at index 0. --%>
<c:setArray var="row" index="0" value="0"/>
<c:setArray var="row" index="1" value="1"/>
<c:setArray var="myArray" index="0" value="${row}"/>

<%-- Create the second row, assign it values at index 2 and 3.
<%-- Assign the row to myArray at index 0. --%>
<c:setArray var="row" index="0" value="2"/>
<c:setArray var="row" index="1" value="3"/>
<c:setArray var="myArray" index="1" value="${row}"/>

${myArray} now contains [[0,1], [2,3]].

We can use the JSP Expression Language to access each array element so

<c:out value="${myArray[0][0]}"/>
<c:out value="${myArray[0][1]}"/>
<c:out value="${myArray[1][1]}"/>
<c:out value="${myArray[1][2]}"/>


0 1 2 3

Note that each index of 'myArray' refers to a row, each of which is a
one-dimensional array.  By induction, this model extends to
multi-dimensional arrays where each element of an array may refer to
another one-dimensional array whose elements may themselves each refer
to another one-dimensional array, and so on.

What do you think?


> -----Original Message-----
> From: Simon Benzekri 
> Sent: June 2, 2004 10:10 AM
> To: Tag Libraries Users List
> Subject: RE: [JSTL] Indexed array variable
> Good idea but how will multi-dimensional arrays be populated?
> Simon 
> -----Original Message-----
> From: Helios Alonso [] 
> Sent: Wednesday, June 02, 2004 9:48 AM
> To: Tag Libraries Users List
> Subject: RE: [JSTL] Indexed array variable
> It would be great.  I think it's very appropiate (very common 
> idea even for 
> non-programmers, easy to implement).
> By example (my case):  I want to make a calendar and would 
> like to make it 
> very generical.  If I could use associations with taglibs, I'd make 
> something that gives me dates (or months, weeks, and days), 
> and another 
> bean associating days to properties.  It helps mantaining the 
> calendar code 
> independent from the "properties" code.  And properties could be 
> associations too:
> 'holiday' -> boolean
> 'holidayname' -> name
> 'itemscount' -> int
> and so on.
> The JSP would poduce HTML for the calendar, but guided by the 
> properties of 
> each day (holidays in red, days with items with a link, etc.)
> At 09:25 02/06/2004 -0400, you wrote:
> >I think you're right.  Just like no JSTL tag exists to create an 
> >associative array (a bean or a map indexed by string), no JSTL tag 
> >exists that can explicitly allocate an indexed array.  <jsp:useBean> 
> >can create both associative and indexed arrays, and <c:set> can set 
> >associative array properties, but not indexed array 
> elements.  I think 
> >the only solution, then, is to create my own tag handler similar to 
> ><c:set> that can assign array elements.  Of course, this is 
> >non-standard, but will solve my problem.
> >
> >Will the next version of JSTL enhance <c:set> to permit the 
> assignment 
> >of array elements?
> >
> >Derek
> >
> > > -----Original Message-----
> > > From: Bill Siggelkow []
> > > Sent: June 1, 2004 8:49 PM
> > > To: 'Tag Libraries Users List'
> > > Subject: RE: [JSTL] Indexed array variable
> > >
> > >
> > > I don't think that JSTL is going to be able to "create" array 
> > > elements. I think you will need to allocate the array 
> ahead of time. 
> > > Maybe someone else can clarify this a little more.
> > >
> > >
> > > Bill Siggelkow
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: Derek Mahar []
> > > Sent: Tuesday, June 01, 2004 5:10 PM
> > > To: Tag Libraries Users List
> > > Subject: [JSTL] Indexed array variable
> > >
> > > How does one create and assign elements to an indexed 
> array variable 
> > > in JSTL or the Expression Language? <c:set> seems lacking in this 
> > > respect.
> > >
> > > Derek
NOTICE: This email contains privileged and confidential information and is intended only for
the individual to whom it is addressed. If you are not the named addressee, you should not
disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail
if you have received this transmission by mistake and delete this communication from your
system. E-mail transmission cannot be guaranteed to be secured or error-free as information
could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.

AVIS: Le présent courriel contient des renseignements de nature privilégiée et confidentielle
et n'est destiné qu'à la personne à qui il est adressé. Si vous n'êtes pas le destinataire
prévu, vous êtes par les présentes avisés que toute diffusion, distribution ou reproduction
de cette communication est strictement interdite.  Si vous avez reçu ce courriel par erreur,
veuillez en aviser immédiatement l'expéditeur et le supprimer de votre système. Notez que
la transmission de courriel ne peut en aucun cas être considéré comme inviolable ou exempt
d'erreur puisque les informations qu'il contient pourraient être interceptés, corrompues,
perdues, détruites, arrivées en retard ou incomplètes ou contenir un virus.  

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message