How to create a custom message and display it in a Maximo application

This entry is part of the Maximo Java Development series.

A typical need during Maximo application customization is the ability to display a message on the GUI.

The first step is to define the custom message. Open the Database Configuration application and select Messages for the Action menu. Create a new entry filling the required info:
Here is a screenshot of the new message.

Now that you have defined your message in the database it's time to show it.
The technique to display the message is different whether you are in an AppBean or in a Mbo class.

If you are in a custom application bean class (extending AppBean) those two Java lines will bring up the custom message box.

String params[] ={"Hi there!"};
  clientSession.getCurrentEvent(), "MyGroup", "HelloMsg", params);

As you can see the {0} tag in the message will be replaced with the string 'Bruno' defined in the params array. Obviously it is possible to define multiple tags.

It is also possible to display this message box when an exception is thrown. For example the following two rows will display the same message but will also log a stacktrace in the system logs.

String params[] ={"Hi there!"};
throw new MXApplicationException("MyGroup", "HelloMsg", params);

If you are in an Mbo or MboSet (businessobject project) you can 'attach' the message to the MboSet with the MboSet.addWarning(MXException e) method.

String params[] ={"Hi there!"};
this.addWarning(new MXApplicationException("MyGroup", "HelloMsg", params));

Alternatively it is possible to throw an MXApplicationException like this.

String[] params = {"Hi there!"};
throw new MXApplicationException("MyGroup", "HelloMsg", params);

Labels: , , , ,