Re: Trouble calling methods in a Struts 2 action
Christopher Maloof <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On 11/6/2009 2:44 PM, Daniel Dekany wrote:
> Friday, November 6, 2009, 6:32:05 PM, Christopher Maloof wrote:
>
>
>> I'm just starting to use FreeMarker (2.3.15) with Struts 2.1.8. It
>> mostly works great: my templates are retrieving bean information with no
>> problem. However, I can't figure out how to call methods defined in my
>> action classes -- in fact I have no idea why it isn't working as I expected.
>>
>> If my action class looks like this:
>>
>> public class MyAction extends MyActionSupport {
>> public String getMyValue() {
>> return "hello";
>> }
>> public String myMethod() {
>> return "world";
>> }
>> }
>>
>> then ${myValue} or ${myValue.toUpperCase()} works fine, as does
>> <@s.property value="myMethod()"/>, but ${myMethod()}results in a
>> "Expression myMethod is undefined" error. The docs
>> (http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_methodcall)
>> seem to think this should be perfectly fine, as far as I can tell.
>>
>> Any idea why Freemarker isn't seeing the top-level action methods unless
>> I use<@s.property>?
>>
>
> What's the data-model in Struts? It had to be the MyAction instance,
> or else the methods will no be visible.
The template is mapped to the correct action, if that's what you're
asking. These things work:
${myValue} (indirect access to bean getter)
${myValue.toUpperCase()} (method call on object)
<@s.property value="myMethod()"/> (Struts tag calling a method)
But these things don't:
${myMethod()}
${getMyValue()} (plain method calls as described in the docs)
Chris
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user