Last Updated:

Including Your Own External Java Code in Table Layouts

Andy Lapping Tip

Overview

As you may be aware Rhapsody allows you to use Java code in tables in various ways. One of those is writing your own methods directly in the table layout itself. However that method has its limitations, the greatest being that you are limited to that single method body. If you want to do somerthing more complex such as a supporting function that uses recursion, you have to use one of the other Java based methods (such as writing helpers in a plugin and calling those).

Or do you ?

Including External Code

It turns out there is a way to include your own external libs/classes in a table layout by adding to the classpath for that layout. 

In the properties for the table layout you will find one called Model::TableLayout::UserDefinedImplementationXML.

As the name suggests it is XML that captures information about any User Defined Method entries in the layout. That XML will have one entry for each column of type 'User Defined Method', capturing such things as the list of Imports, the method body and .. the classpath 

Simple edit that property (copy and paste it to a text editor to make the job easier) and add new <PATH> </PATH> entries into the Classpath section for the column where you want to call the external code. You can also edit the list of Imports there too (which I find easier than using the UI). You could also edit the code but I find doing that easier by copying and pasting between Rhapsody and Eclipse which allows me to test my functions easily before adding them to Rhapsody. Once you have the classpath your User Defined Method column can access any static function from that classpath:

Accessing External Java Code in Table Layouts