请求属性中带有嵌套HashMap的jstl forToken [英] jstl forToken with Nested HashMap in request Attribute
问题描述
我有一个带有键(标签,大小等)的HashMap(ecd_date,owned_by等)的HashMap(hshFields).我可以这样访问:
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}" />
(注意:我必须使用JSTL而不是EL)
(note: I must use JSTL and not EL)
the about发出字段的标签"(在XML映射中维护),即:
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
我现在想使用jstl forToken遍历嵌套的HashMap.但是我无法使它正常工作.这是我的尝试之一:
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>
这是因为语法不正确还是希望因为我没有EL功能而无法正常工作吗?
Is this not working because Of incorrect syntax or hopefully not because I don't have EL capability??
编辑 根据我在下面的skaffman的回复,可以:
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>
,输出为:
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>
我得到以下输出:
Label for owned_by : Commitment Owner
Label for ecd_date : Estimated Completion Date
Label for commitment_id : Commitment Number
推荐答案
您的语法不太正确,应该正确
Your syntax isn't quite right, it should be
<c:out value="${hshFields[curField].label}" />
而不是
<c:out value="${hshFields.${curField}.label}" />
不允许使用类似嵌套的EL表达式.
Nested EL expressions like that isn't permitted.
已更新:之所以仅在循环中的第一次迭代中起作用,是因为您的items
列表中有空格和逗号,而delims
仅处理逗号.因此将循环更改为
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"
而不是
items="commitment_id, owned_by, fndsource"
否则,空格将成为各个循环值的一部分.
Otherwise, the spaces will form part of the individual loop values.
这篇关于请求属性中带有嵌套HashMap的jstl forToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!