Expression undefined while iterating over list (Returned by a static method) in ftl with struts 2.3.16

StackOverflow https://stackoverflow.com/questions/21498603

Question

We had following working ftl which was deployed on struts 2.0.11

FTL::

[#list allPaymentMethods?sort as item]
     options = options + "<option  name='${item?string}' value='${item?string}' [#if paymentMethods.contains(item)]selected='selected'[/#if]>${item?string}</option>";
[/#list]

The corresponding action class has following method which returns a non null list.

public static List<String> getAllPaymentMethods()

This implementation was working with struts 2.0.11 and freemarker 2.3.10.

It starts giving Expression undefined error while parsing ftl after we upgraded to struts 2.3.16 and freemarker 2.3.19.

The error goes away if we make the static method to an instance method.

public List<String> getAllPaymentMethods()

We were expecting struts/freemarker to be backward compatible.

It seems struts-2.3.16/freemarker-2.3.19 does not support static getter methods on action class. Has anyone observed similar issue? Or the way we have been using static getters is not recommended?

While migrating, it is very difficult to go through all ftls/Java code to identify and convert such static getter methods to instance methods.

Is there any other alternatives we can use to migrate such code/ftl?

Was it helpful?

Solution

Static method access has been disabled by default since around 2008-2009 with Struts 2.1+.

https://cwiki.apache.org/confluence/display/S2WIKI/Troubleshooting+guide+migrating+from+Struts+2.0.x+to+2.1.x#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-RefactorusageofstaticmethodsviaOGNL

Nutshell: you must explicitly enable static method access.

This change was detailed in both the release notes and the migration guide.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top