tags:

views:

66

answers:

1

I have a HashMap (hshFields) of HashMaps (ecd_date, owned_by, etc..) with keys (label, size, etc..that I access as such:

<c:out value="${hshFields.ecd_date.label}" />
<c:out value="${hshFields.owned_by.label}" />
<c:out value="${hshFields.fnd_source.label}" />

(note: I must use JSTL and not EL)

the about spits out the a "label" of the field (maintained in an XML map) i.e.:

commitment_id = Commitment Id 
owned_by = Commitement Owner
fndsource = Funding Source

I'd like to now use a jstl forToken to loop over the nested HashMap. But I can not get it to work. Here is one of my attempts:

 <c:forTokens items="commitment_id, owned_by, fndsource" delims="," var="curField">
    The Field Label is: <c:out value="${hshFields.${curField}.label}" /> <br />
    The Field Sixze is: <c:out value="${hshFields.${curField}.size}" /> <br />
</c:forTokens>

Is this not working because Of incorrect syntax or hopefully not because I don't have EL capability??

EDIT OK based on skaffman's response below I have:

<c:forTokens items="owned_by, ecd_date, commitment_id" delims="," var="curField">
  Label for <c:out value="${curField}" /> : <c:out value="${hshFields[curField].label}" /><br></br>
</c:forTokens>

and the output is:

Label for owned_by : Commitment Owner
Label for ecd_date : 
Label for commitment_id : 

It seems to be working only on the first token because if I use the following:

Label for owned_by : <c:out value="${hshFields.owned_by.label}" /> <br></br>
Label for ecd_date : <c:out value="${hshFields.ecd_date.label}" /> <br></br>
Label for commitment_id : <c:out value="${hshFields.commitment_id.label}" /> <br></br>

I get this output:

Label for owned_by : Commitment Owner
Label for ecd_date : Estimated Completion Date
Label for commitment_id : Commitment Number
+3  A: 

Your syntax isn't quite right, it should be

<c:out value="${hshFields[curField].label}" />

rather than

<c:out value="${hshFields.${curField}.label}" />

Nested EL expressions like that isn't permitted.

updated: The reason it's only working for the first iteration in the loop is because you have spaces as well as commas in your items list, and the delims only handles the commas. So change the loop to

items="commitment_id,owned_by,fndsource"

rather than

items="commitment_id, owned_by, fndsource"

Otherwise, the spaces will form part of the individual loop values.

skaffman
@skaffman. Thanks. I made the change however, I am now only getting the label for my first token. The succeeding ones spit out a blank. I have edited my post above.
jeff
@jeff: See edited answer.
skaffman
@skaffman. SWEET! thanks.
jeff