[英]How to retrieve dynamically generated name tag for s:set for Struts2?
How can I retrieve a dynamically generated name tag for <s:set> on Struts 2?如何在 Struts 2 上为 <s:set> 检索动态生成的名称标签?
Eg: In my action class I have an object (currency) that have this fields: 'id' and 'symbol'.例如:在我的操作 class 中,我有一个 object(货币),其中包含以下字段:'id' 和 'symbol'。 So in my view page I can use this:
所以在我的视图页面中我可以使用这个:
<s:iterator value="currency">
<s:set name="var_%{id}" value="symbol"/>
<s:set name="total_%{id}" value="%{0.0}"/>
</s:iterator>
So I can use this to create these PageContext variables like "var_BRL", "var_USD", "var_MXN" and "total_BRL", "total_USD", "total_MXN" etc. If I write the following code:所以我可以使用它来创建这些 PageContext 变量,如“var_BRL”、“var_USD”、“var_MXN”和“total_BRL”、“total_USD”、“total_MXN”等。如果我编写以下代码:
<s:property value="#var_USD"/> = <s:property value="#total_USD"/>
I'm able to retrive a result like:我可以检索如下结果:
USD = 0.0
I'm using these #total_XXX variables to sum some values under some conditions presented by another iterator, in a way that I'll have at the end of this other iteraction, a result of the total spent in every currency (BRL, USD, MXN etc).我正在使用这些 #total_XXX 变量来对另一个迭代器呈现的某些条件下的一些值求和,这种方式在另一个迭代结束时会得到,这是每种货币(巴西雷亚尔、美元、 MXN 等)。
But when I try to retrieve these values dynamically, nothing is rendered.但是当我尝试动态检索这些值时,什么都没有呈现。 Following is the code I'm using to retrieve the values from these variables, at the end of my page.
以下是我用来从这些变量中检索值的代码,位于页面末尾。 I don't understand OGNL very well, so I've tryed different arrangements like the ones below and had no success with any of them:
我不太了解 OGNL,所以我尝试了以下不同的安排,但都没有成功:
<s:iterator value="currency">
<s:property value="#var_%{id}"/> = <s:property value="#total_%{id}"/>
<s:property value="#%{var_%{id}}"/> = <s:property value="#%{total_%{id}}"/>
<s:property value="%{#var_%{id}}"/> = <s:property value="%{#total_%{id}}"/>
</s:iterator>
Is there a solution to retrieve these values in the PageContext?是否有在 PageContext 中检索这些值的解决方案? Or can I only solve this inside my Action?
还是我只能在我的 Action 中解决这个问题? I've searched so many posts but I couldn't find anything.
我搜索了很多帖子,但我找不到任何东西。
Thank you!谢谢! LZ
LZ
discussing with a friend, I found the proper OGNL expression to call for the dynamically created variables names at the end of my code:与朋友讨论时,我找到了正确的 OGNL 表达式,可以在代码末尾调用动态创建的变量名称:
<s:iterator value="currency">
<s:property value="#attr['var_'+id]"/> = <s:property value="#attr['total_'+id]"/><br>
</s:iterator>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.