Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke Java method with parameters from Freemarker

The following FTL markup works fine for me and calls getWidgets() in my server-side JiveActionSupport object:

<#list widgets! as widget>
  -- do something with widget.sku
</#list>

However, I really need an inner list that depends on a property of widget, something like this:

<#list widgets! as widget>
  <#list manufacturers(widget.sku)! as manufacturer>
  -- do something with manufacturer
  </#list>
</#list>

I have tried to implement the server-side code, as either:

public List<Manufacturer> getManufacturers(int sku);
public List<Manufacturer> getManufacturers(String sku);

But both result in 'Expression manufacturers is undefined at line 123'.

How can you pass parameters to methods of the current JiveActionSupport object? Thanks.

like image 448
jarmod Avatar asked May 07 '12 17:05

jarmod


2 Answers

The thing that possibly confused you here is that getFoo() can be called as foo, but getFoo(param) can't be called as foo(param), only as getFoo(param). But this is just how JavaBeans work; getFoo() defines a JavaBean property, while getFoo(params) doesn't.

Anyway, if getManufacturers is the method of the data-model (root) object, then (assuming proper object wrapping) you should be able to call it as getManufacturers(param). You don't need to start it with action. in principle.

like image 54
ddekany Avatar answered Sep 29 '22 02:09

ddekany


In general, it looks as if you need to do this as follows:

<#list action.getManufacturers("123")! as manufacturer>
  -- do something with manufacturer
</#list>

In particular, while you can use things in FTL to invoke the server-side method getThings(), you need to use action.getThing("123") to invoke the server-side method getThing(String).

like image 23
jarmod Avatar answered Sep 29 '22 04:09

jarmod