Re: Trouble calling methods in a Struts 2 action
Christopher Maloof <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
You were right, the Struts list was the place to ask. The trick is to
use the built-in "action" variable to refer to the action directly, like
${action.myMethod()}. I'm not sure why the public methods aren't made
available otherwise, but it's an easy enough solution.
http://markmail.org/message/upuwtwdd45cqwrwb
Thanks,
Chris
On 11/7/2009 1:20 AM, Daniel Dekany wrote:
> Thing is, FreeMarker is very flexible when it comes to building the
> data-model (mostly done with so called object wrapping), and I don't
> know what the Struts guys done. If they use the action object itself
> to be the data-model, with some typical object wrapper setup the
> public methods are visible. But then it seems they decided that they
> will not be visible... they can do that, it's up to them. So maybe
> it's better to ask them.
>
>
> Friday, November 6, 2009, 9:22:36 PM, Christopher Maloof wrote:
>
>
>> 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";
>> }
>> }
>>
> [snip]
>
>> 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
>>
>
>
--
Christopher Maloof, M.S.
Software Developer, Medical Oncology, Informatics Shared Resource
Kimmel Cancer Center, Thomas Jefferson University
Phone: 215-503-9275 Fax: 215-955-9093
------------------------------------------------------------------------------
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