简体   繁体   English

如何检索为 s:set 为 Struts2 动态生成的名称标签?

[英]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.

相关问题 设定方法 <s:param> 的价值 <s:url> 在struts2中使用javascript动态标记 - How to set <s:param> value of <s:url> tag dynamically using javascript in struts2 如何检索的数据 <s:radio> 内 <s:iterator> 标记到Struts2的动作中 - How to retrieve the data of <s:radio> within <s:iterator> tag into Struts2's action 如何在不使用 s:iterator 的情况下使用 Struts2 标签检索 HashSet 的元素 - How to retrieve the elements of HashSet using Struts2 tag without using s:iterator 如何使Struts2在浏览器中加载动态生成的pdf文件 - How to make struts2 load a dynamically generated pdf file in browser 如何在JSP中使用Struts2迭代器动态设置end属性 - How to set end attribute dynamically with Struts2 iterator in JSP 如何在自定义的Struts2标记中读取属性的值? - How to read an attribute's value in a custom Struts2 tag? 比较Struts2中的字符串 <s:if> 标签 - Comparing Strings in Struts2 <s:if> Tag s:select struts2标签问题 - s:select struts2 tag issue Struts2的 <s:select list=“”> 无法动态工作 - Struts2 <s:select list=“”> not working dynamically Struts2 - 如何在验证错误后使用提交的值重新填充具有动态生成的字段名(通过表达式)的表单 - Struts2 - How to repopulate form having dynamically generated fieldnames (via expression) with submitted values after validation error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM