简体   繁体   English

从.JSP文件中的动作类调用方法,该方法在Struts 2中获取Enum参数

[英]Calling a method from action class in .JSP file that takes an Enum parameter in Struts 2

I'm using the Struts 2 framework. 我正在使用Struts 2框架。 I have an action class and a JSP page. 我有一个动作类和一个JSP页面。 The class has the following two methods: 该类有以下两种方法:

public String foo(String s)
{
    return s + s;
}

public String bar(SomeEnumClass EnumType)
{
    switch(EnumType)
    {
         //Return a string depending on the type. 
    }
}

I can call the first method using this in my .JSP file: 我可以在我的.JSP文件中调用第一个方法:

<s:property value="%{foo('some string here')}"/>

and it will correctly return to my .JSP: 它会正确返回我的.JSP:

some string heresome string here

I'm now trying to figure out how to call the second method. 我现在正试图弄清楚如何调用第二种方法。 How can I let Struts 2 know the "string" EnumTypeA should be typecasted to the corresponding EnumType ? 我怎样才能让Struts 2知道“字符串” EnumTypeA应该被类型EnumType相应的EnumType

<s:property value="%{bar('EnumTypeA')}"/>

Struts offers a lot of built-in type conversion, but string to enum doesn't appear to be one of them? Struts提供了很多内置的类型转换,但是enum字符串似乎不是其中之一?

您可以使用以下表示法从JSP访问枚举:

<s:property value="bar(@package.SomeEnumClass@EnumTypeA)"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM