tags:

views:

62

answers:

1

Not able to access static fields with OGNL with struts2

<s:checkbox  name="operation" fieldValue="@com.xx.xxx.webapp.action.EntryAction@OPERATIONAL" />

The above turning to HTML as below

<input type="checkbox" name="operation" value="@com.xx.xxx.webapp.action.EntryAction@OPERATIONAL" id="entry_operation"/>

instead the static constant declared as

com.xx.xxx.webapp.action.EntryAction.OPERATIONAL = "OPERATIONAL";

I've the constant <constant name="struts.ognl.allowStaticMethodAccess" value="true"/> set correctly

+2  A: 

Your problem is not related to static fields, but to basic Struts2 tag syntax. The code is wrong on several levels.

First, its the value attribute which you should be using, so that Struts2 interpret what's inside as something to evaluate and render (fieldValue is only for those rare cases in which you need to write a fixed ad-hoc value="" attribute in your html).

Second, you should not use static fields if you are learning Struts2, understand the basic and typyical scenarios first.

Third, it makes little sense to use that string as value of a checkbox, which has just two values (true and false).

leonbloy