Struts2 accessing enum from JSP

余生长醉 提交于 2019-11-29 02:53:54

问题


I have the following class

package com.test;

public class SomeClass {
   public enum COLOR {RED,BLUE}
}

I want to access values of COLOR enum in my JSP. I've tried the following code but it doesn't work.

<s:property value="@com.test.SomeClass.COLOR@RED"/>
<s:property value="@com.test.SomeClass@COLOR.RED"/>

Any body came across this issue before? [I've already enabled static method access in struts.xml]


回答1:


For enum-s there is not need to enable static method access.

Enum-s can be accessed using @ sign like that:

<s:property value="@package.ENUM@enumvalue"/>

In your case since you are declaring enum inside class use $ sign to refer to your enum.

<s:property value="@com.test.SomeClass$COLOR@RED"/>


来源:https://stackoverflow.com/questions/16063819/struts2-accessing-enum-from-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!