Struts 2动态变量

编程入门 行业动态 更新时间:2024-10-23 17:35:22
本文介绍了Struts 2动态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用set tag在Struts2中创建动态变量

I'm trying to create a dynamic variable in Struts2 using set tag

<s:set var="myNum" value="numConst" /> <s:set var="number" value="%{getText('@xxx.CommonConstant@'+#myNum)}" />

numConst 将返回检索到的动态值来自数据库。例如,如果值为NINE,则数字应为 @ xxx.CommonConstant @ NINE

numConst will return a dynamic value that retrieved from database. For example, if the value is NINE then number should be @xxx.CommonConstant@NINE

我已设置我的java类中的值,以便 @ xxx.CommonConstant @ NINE 将返回 9 。

I have set the value in my java class so that @xxx.CommonConstant@NINE will return 9.

到目前为止,如果我使用

So far, the value can be displayed with no problem in text tag if I use

<s:text name="%{getText(#number)}" />

它将返回 9 但显示不正确当我尝试使用属性标记时

It will return 9 but it displayed incorrectly when I tried using property tag

<s:property value="%{getText(#number)}" /> <s:property value="%{#number}" /> <s:property value="#number" /> <s:property value="%{getText('%{getText(#number)}')}" />

以上所有示例都将为我提供 @xxx的值。 CommonConstant @ NINE 。我试图从属性标记中获取值的原因是因为我想要复制正确的方法来显示值,以便我可以在if标签中使用它们,如下例所示:

Which all of the above examples will give me the value as @xxx.CommonConstant@NINE. The reason I try to get the value from property tag is because I want to copy the correct way on how to display the value so I can use them in if tag like below examples:

<s:if test="#number == 9"> do something </s:if>

<s:if test="%{getText(#number)} == 9"> do something </s:if>

CommonConstant:

package xxx; public abstract class CommonConstant { public static final int NINE = 9; public static final int NINEONE = 91; public static final double ADMIN_PGM = 1.4; // ... omitted ... }

任何人都可以提供帮助我?

Can anybody help me?

推荐答案

这似乎是一种解决方法,但你可以使用 attr 评估字符串。

It seems like a workaround but you can use attr to evaluate string.

<s:set var="myNum" value="numConst" /> <s:set var="number" value="'@xxx.CommonConstant@'+#myNum" /> <s:property value="#attr[#number]"/> <s:if test="#attr[#number] == 9"> do something </s:if>

更多推荐

Struts 2动态变量

本文发布于:2023-11-28 07:28:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641472.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   动态   Struts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!