Creating Messages

Top  Previous  Next

In MoreMotion environment creating a message to display to the end user means creating an ADOM. If you want to warn the end user about an invalid input you can create an ADOM that contains the message text.

  ADOM msg = request.newRequestADOM("msg");
  msg.setNodeValue("text","Invalid Value!") 

 
If the data source "msg" is used in the page to be displayed the following XML will be created by the MoreMotion.

   <root>
    <msg
      <text>Invalid Value!</text>
    </msg>
  </root> 

 

To show the message on the page you can bind the value of a text element to /msg/text node as follows.

<xsl:value-of select="/root//msg/text" />
 

As the requirements increase, like providing a message id, message details, handling multiple messages and supporting multi-lingual message, this simple example can get complicated.

 

Creating Multi-Lingual Messages using MoreMotion API

To create multi-lingual messages, you can use the provided methods in MoreMotion API.

// In a Service

request.createMessage(unit-name, message-id, message-arguments, message-details);

 

// In a Process 

createMessage(message-id, message-arguments, message-details);

 

createMessage() methods create a new Request ADOM for the message if not already created and adds the given message in it.

unit-name 

The Name of the reporting unit. This name will be used to name the ADOM to be created and the resource associated with it. This parameter is not available in the process createMessage() method because the unit-name is taken from the process definition file.

message-id 

Either a message text or a resource Id. The message text will be taken from the resource file <unit-name>.res with this Id. If the resource file has multi-language support then the correct language version of the message text will be taken from the resource file depending on the language of the page to be displayed.

If no resource is found with the given id in the resource file then message-id is used as the message text.

message-arguments 

The message arguments which will be used to replace argument symbols (%0, %1, etc.) existing in the message text.

message-details 

Either an Exception object that keeps the original exception or a String object that keeps the message details.

The XML structure of the created message datasource is as follows:

  <unit-name_messages>
    <message id="message-id">
      <text>Message text taken from the resource file with the given message-id</text>
      <unitname>Given unit name</unitname>
      <details>
        Message Details. Either the Stack Trace of the orginal exception or the given details as String
      </details>
    </message>
  </unit-name_messages> 

 

Example:

  try {
    ...
    ...
  } catch (Exception e) {
    ADOMNode msg = request.createMessage("myunit","MISSING_TABLE", 
                     new String[]{dbName, tableName}, e);
    // You can add additional info to the created message ADOM
    msg.setNodeValue("extrainfo", "extra info ...");
 
    // Display the default Error Page
    request.generateDefaultErrorPage();
 
    // Display your own Error Page. You can develop your own 
    // error page XSL Style Sheets by copying and modifying the style sheets under
    // "ROOT/moremotion/error/" directory.
    request.generatePage("MyErrorPage");
    return;
  } 

 

The Message Id "MISSING_TABLE" should exist in resource file ROOT/WEB-INF/MM-INF/resources/myunit.res.

myunit.res file

  <root>
    <item id="MISSING_TABLE">
      <en>Table "%0" is missing in database "%1"</en>
      <de>Tabel "%0" is nicht verfuegbar im datenbank "%1"</de>
    </item>
  </root>