Jelly - how to call java method with parameters from jelly tag

1.2k Views Asked by At

I have the following entry in my .jelly file:

<j:forEach items="${instance.getVerdictCategoriesList()}" var="p">
    <f:entry title="${%Started}"                             
             field="${p.verdictValue}">
             <f:textbox name="${p.verdictValue}"
                        value="${instance.returnDefaultZeroValue()}"
                        default=""/>
    </f:entry>

Currently I'm calling the ${instance.returnDefaultZeroValue()} and it works.

I want to call a method with multiple parameters. How do I do that?

Like: value="${instance.getGerritReportingValueForCustomLabel(${p.verdictValue})}" but that fails with a "can't parse jelly" error.

2

There are 2 best solutions below

1
Jesse Glick On BEST ANSWER

I suppose you meant

value="${instance.getGerritReportingValueForCustomLabel(p.verdictValue)}"

The ${…} syntax introduces interpolation of JEXL expressions into what would otherwise be treated as a literal string. It is not part of JEXL itself.

0
Swapnil Kashid On

There are two ways of calling Java method using Jelly file Following are two Objects are used

  1. Descriptor: As you now know, Descriptor is configuration class this object points to. So from jelly at any point, you can call the method from your Descriptor class.

  2. Instance: This is the object currently being configured on the configuration page. Null if it’s a newly added instance. Means by using this you can call the methods from your Action class. Like getters of field attribute.

You can bind object with jelly using

<st:bind var="backend" value="${descriptor}"/>

OR

<st:bind var="instance" value="${instance}"/>

The method can be called as backend.{backend method name}().

if you are using this from JavaScript then you need use @JavaScriptMethod annotation over the method being called.