Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2 accessing enum from JSP

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="@[email protected]"/>

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

like image 823
Dev Blanked Avatar asked Apr 17 '13 15:04

Dev Blanked


1 Answers

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"/>
like image 126
Aleksandr M Avatar answered Oct 13 '22 04:10

Aleksandr M