我有一个hashmap(hshfields)的hashmap(ecd_date,owned_,etc.),其中包含密钥(标签、大小等)。我可以这样访问:
<c:out value="${hshFields.ecd_date.label}" />
<c:out value="${hshFields.owned_by.label}" />
<c:out value="${hshFields.fnd_source.label}" />
(注:我必须使用JSTL而不是EL)
about吐出字段的a“标签”(在XML映射中维护),即:
commitment_id = Commitment Id
owned_by = Commitement Owner
fndsource = Funding Source
我现在想使用JSTLfortoken循环嵌套的哈希映射。但我不能让它工作。以下是我的一个尝试:
<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>
这是否因为语法错误而不起作用,或者希望不是因为我没有EL功能??
编辑
好吧,根据斯卡夫曼下面的回答,我有:
<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>
输出为:
Label for owned_by : Commitment Owner
Label for ecd_date :
Label for commitment_id :
它似乎只在第一个令牌上工作,因为如果我使用以下令牌:
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>
我得到这个输出:
Label for owned_by : Commitment Owner
Label for ecd_date : Estimated Completion Date
Label for commitment_id : Commitment Number