Accessing object's method in OpenMRS JSP views

I have been having an issue configuring jsp views in openmrs for method calls with parameters.

I want to be able to do something like this on my jsp:

<li>${myObjectInstance.method(paramerer)}</li>

And this will print out a sort of value. I am not doing this in a module on platform version 1.11.4. I would appreciate suggestions on how to go about this, thanks.

JSTL intentionally does not allow you to do this; you can only access properties on the object via getters.

If you want to be able to run custom Java code on a JSP page, the correct way is for you to write a custom tag library.

You can see how this is done in openmrs-core (this is being moved to the legacyui module in a later release) here:

The quick hack way is to interpolate a snippet of Java code like this (this code snippet is from memory, you’ll have to test):

<%= ((MyClass) pageContext.get("myObject")).method(parameter) %>
1 Like