Prompting for variable values

We designed the RPE Launcher User Interface to be a generic, good for all UI that would be easily used by any RPE user. And while we met the first goal, the UI is indeed very generic, we haven’t really made the UI as simple as many users were expecting.

One of the things requested often is the ability to prompt the end-user ( the person generating the documents) to enter the variable values. We are working to improve the RPE user experience but in the meantime there is a nice little trick that provides “variable prompts” to any RPE version.

The solution is to use JavaScript to invoke Java code for displaying an input dialog.

The code uses Swing and this means it is quite different from the RPE Launcher/Studio UI which uses Eclipse JFace and SWT. And while the JFace/SWT UI looks better and is faster, for the task at hand Swing is to be preferred since its much simpler to code from Java Script.

To get a variable value from the user the simplest code to use in the variable’s assignment expression is :

// you can calculate this value
var defaultValue = "Some value";

// the first argument is the label of the editor field while the second is the default value to put in the field
var input = javax.swing.JOptionPane.showInputDialog('Enter the value for the XYZ variable : ', defaultValue);

// return the value provided by the user

There are various flavors of the showInputDialog function including one that allows the user to select the value from a list instead of typing it and customize other aspects of the dialog such as it’s title and icon.

var options = new java.util.ArrayList();
options.add( "Project A");
options.add( "Project X");
options.add( "Project Z");

// 1st argument is parent component - use null
// 2nd argument is the label of the selection
// 3rd argument is the dialog's title
// 4th argument is the message type
// 5th argument is the icon  - if null a default icon matching the message type will be used
// 6th is the list of values
// 7th argument is the initial value to select from the list
var input = javax.swing.JOptionPane.showInputDialog( null, 'Select the the project to use: ', 'RPE Variable Prompt',  javax.swing.JOptionPane.QUESTION_MESSAGE, null, options.toArray(), "Project X");

// debug message
java.lang.System.out.println( "You entered: " + input);

// return the value provided by the user

This results in the following dialog being shown to the user:

The example template is available here. In the example I ask for the name of the author of the document, which the user has to type, and a project name which the user can select from a list. For the default value of the author’s name I use the login name of the current user as obtained from the system.For debug purposes I print the value read from the user in the console.

NOTE if you want to use this technique on your templates I suggest grouping all the assignments at the beginning of the template so that document generations are not waiting for an answer from a user that left to grab a cup of coffee expecting the document will be finished by the time he/she returns. Another recommendation is to mark the variable as internal such that it does not show up in the Document Specification view.


Author: Dragos Cojocari

Architect for Rational Publishing Engine

8 thoughts on “Prompting for variable values”

  1. Is it possible to use the “author name” type input dialog but for multiple fields; meaning having the user enter their name, the document title and version number all in one pop-up?

  2. I have a template that has been using showInputDialog to obtain user input for a while now. Today I ran into an issue where my template aborted with an error: Exception in thread “Thread-149” java.awt.AWTError: Assistive Technology not found:

    I checked the launcher/studio .ini files to be sure they were still pointing to the JRE that was installed with RPE and they are. I have tried creating a new template with just a javascript container and used the code snippet from above. RPE won’t even let me save the code if I have the javax.swing.JOptionPane.showInputDialog line active. RPE isn’t throwing any errors that I can see, it just won’t save the edits.

    I am using RPE version

    Any idea why this broke?

    1. Hey Jamie,

      the first thing I try in this scenarios is to delete the RPE workspace. Close all RPE instances and then delete the RPE_ folders in %APPDATA%\IBM\Rational


      1. I don’t know anything about RPE workspaces, so I didn’t delete those. I did close all RPE instances and then delete the RPE_* folder in the APPDATA folders. I am still having problems. If I create an RPE template that only has a container with a JavaScript Code element in it, then try putting the following code in the element, I can’t click the “OK” button on the editor to save it:

        java.lang.System.out.println(“test 2!!!”);
        var input = javax.swing.JOptionPane.showInputDialog(“give me your weak”);
        java.lang.System.out.println( “You entered: ” + input);

        I don’t get any errors, it just ignores my button click. If I try to Test the script, it does the output test and test2, but I still can’t save. If I comment out the last 2 lines, I can save.

  3. Hey Jamie,

    I tried this on my installation and it works right. Can you try putting the last 2 lines in a try/catch block?

    java.lang.System.out.println(“test 2!!!”);
    var input = javax.swing.JOptionPane.showInputDialog(“give me your weak”);
    java.lang.System.out.println( “You entered: ” + input);
    catch( err) {
    java.lang.System.out.println( “Error: ” + err);

    Can you also give information on the JRE version you run RPE with? To confirm you are using the JRE shipped with RPE and get this version you can do the following:
    1. in Studio go to Help/About Rational Publishing Engine
    2. Click Installation Details
    3. Click “Configuration” tab
    4. In the tab you will see a list of properties. The interesting ones are:

    C:\Program Files\IBM\Rational\Publishing Engine\studio\\..\jre\bin\j9vm\jvm.dll

    java.vendor=IBM Corporation
    java.version=1.7.0 1.7.0 Windows 7 amd64-64 Compressed References 20150701_255667 (JIT enabled, AOT enabled)
    J9VM – R26_Java726_SR9_20150701_0050_B255667
    JIT – tr.r11_20150626_95120.01
    GC – R26_Java726_SR9_20150701_0050_B255667_CMPRSS
    J9CL – 20150701_255667 J9 VM

    My last request would be to use the DevWorks forum for this type of questions as you will have more people able to answer and some might have run into this issue already.


    1. Thank you Dragos. I will post a question over in DevWorks. With the try/catch block, I still couldn’t get the script editor to close. The JRE in use is the one inside the RPE installation directory. In my case it is version JRE 1.6.0 IBM J9 2.4 Windows 7 x86-32 jvmwi3260sr15-20131016_170922 (JIT enabled, AOT enabled)
      J9VM – 20131016_170922
      JIT – r9_20130920_46510ifx2
      GC – GA24_Java6_SR15_20131016_1337_B170922

      Thanks again for your assistance, hopefully someone over on DevWorks will have some pointers…


      1. Hey Jamie,

        I’ll continue to work with you on this one over on the DevWorks forum but hopefully other people will join us too as here only a handful of people can comment.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s