Search code examples
struts2freemarker

Struts 2 cannot resolve java action method in # tag


There's something I'm been missing in how Struts resolve ftl tag, I have an action with some methods that I'm trying to call from my ftl.

The signature:

<@s.property value="%{someJavaMethod(someVariable)}>

is working fine, but the directive

<#include someJavaMethod(someOtherVariable)>

is giving me this:

----: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> someJavaMethod

and I cant figure out why, since, based on my limited knowledge of struts the signature # has access to the context Map where action properties and methods are stored.

NB: I checked that the problem is not in the someJavaMethod since debugging the code it doesn't even enter into.


Solution

  • You should reference the action to call its method in Freemarker. It is supported by the Struts 2 framework.

    <#include action.someJavaMethod(someOtherVariable)>