Bryan Schmiedeler
Bryan Schmiedeler

Reputation: 3127

Xpages: Error calling java method in a CacheBean in EL

My Xpages app has a cacheBean for application wide settings. I have a managed Bean for a PC document, which has field status of type integer.

In the cacheBean I have a method getPCStatus(Integer status) that when given the number will return the string text of the status.

On my Xpage I have a text field which I want to bind to the result of

cacheBean.getPCStatus(PCBean.status)

so it will return "In Inventory" for a 1 and something else for a 2 etc.

However, the code is throwing an error.

Here is the code:

readonly="true">
<xp:this.value><![CDATA[#{CacheBean.getPCStatus(PCModelBean.status)}]]></xp:this.value>
</xp:inputText>

The error is

Error in EL syntax, property 'value': CacheBean.getPCStatus(PCModelBean.status)

I know I read something about this long ago but cannot remember how to handle this, but cannot find it.

I was wondering if the method getPCStatus should be in the PCBean or in the cacheBean?

Upvotes: 0

Views: 107

Answers (1)

Jesse Gallagher
Jesse Gallagher

Reputation: 4471

The version of EL used n XPages doesn't have support for calling methods with parameters. If getPCStatus() were a zero-argument method, you could call it with #{CacheBean.pCStatus}, presumably, but as it is it's the parameter that's in your way.

There are a few common workarounds: if CacheBean itself implements Map or DataObject, then EL will call the get or getValue method, respectively, with whatever you put after the "." - you could use that to sort of fake method calls.

Alternatively, you could keep CacheBean a POJO (not implementing one of those interfaces) but have the return value from getPCStatus itself be a Map or DataObject, which would take whatever value you pass in (in this case, PCModelBean.status) and do the lookup, with a binding like #{CacheBean.pCStatus[PCModelBean.status]}. DataObjects aren't too bad to write: https://frostillic.us/blog/posts/FE0AE00B7CEC4F8885257D46006CAB68

Or, as an complete alternative to all of this, if you don't need your binding to be read+write, you could use SSJS to call the method.

Upvotes: 3

Related Questions