Show TOC Start of Content Area

Procedure documentation Example for Using Messages  Locate the document in its SAP Library structure

The following example shows how you can use messages created in the Message Editor. In the example, both messages with static text and messages that are dependent on user inputs – that is, messages with dynamic text – are defined.

Description of Example

Users can create a domain in this sample application. They can then enter a number in the next input field and press Click here to validate. If the specified number lies in the previously specified range, the user is informed of this fact in a standard message. If the number does not lie within this domain, the user sees a warning message.

This graphic is explained in the accompanying text

Prerequisites

You have created a Web Dynpro application and defined view “MainView” within a Web Dynpro component.

Procedure

Creating the View

...

Define the view as illustrated below:

This graphic is explained in the accompanying text

Context Creation:

The context that provides the data is created as follows:

...

       1.      Create a context node, UIElem

       2.      Set the propertycardinality to 1..1 for the context node.

       3.      Create the context attributes a, b, and TypeField.

       4.      Set the Type of the context attributes to Integer.

This graphic is explained in the accompanying text

Data Binding

To make the messages dynamic with regard to specification of the domain, the user inputs have to be saved. To do this, the input fields have to be bound to the context.

sss

Object

Object ID

Data Binding to Attribute

Path Within the Context Structure

a

Input Field

A

This graphic is explained in the accompanying text MainView.UIElem.a

b

Input Field

B

This graphic is explained in the accompanying text MainView.UIElem.b

Children_2

Input Field

TypeField

This graphic is explained in the accompanying text MainView.UIElem.TypField

In addition, bind the Children_3 pushbutton to action ValidateAction, which you also have to create.

Creating Messages in the Message Pool

The Web Dynpro tools provide a special message editor for defining messages of different types. 

A message is defined by a specified key, message type, and message text. The message types This graphic is explained in the accompanying text error, This graphic is explained in the accompanying text warning, and This graphic is explained in the accompanying text standard are predefined.

Create the following messages:

Messages Defined in the Message Editor

Message Key

Message Type

Message text

key1

warning

Please enter a number between the range of {0} and {1}!

This graphic is explained in the accompanying text  {0} and {1} are placeholders for the user input (the domain), which changes dynamically.

key2

standard

The value entered is within the valid range.

 

This graphic is explained in the accompanying text

Implementation

Because the messages are only displayed when the user Chooses Click here to validate, the messages must be implemented in the method onActionValidateAction:

Implementierung der Methode onActionValidateAction()

//@@begin imports

import com.sap.tc.webdynpro.progmodel.controller.MessageManager;

import com.sap.test.errorhandlingtest1.wdp.IMessageErrorhandlingTest1;

import com.sap.test.errorhandlingtest1.wdp.IPrivateMainView;

//@@end

//...

 

public void onActionValidateAction(

                       com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent)

  {

    //@@begin

   int i = wdContext.currentUIElemElement().getTypField();

   int a = wdContext.currentUIElemElement().getA();

   int b = wdContext.currentUIElemElement().getB();

  

   MessageManager msgMgr =

         (MessageManager)wdThis.wdGetAPI().getComponent().getMessageManager();

     

   if (a < i && i < b)

      {

         msgMgr.reportMessage(IMessageErrorhandlingTest1.KEY2, null, true);

      }

   else

      {

         Object[] arg ={new Integer(a), new Integer(b)};

         msgMgr.reportMessage(IMessageErrorhandlingTest1.KEY1, arg, true);

      }

    //@@end

  }   

This graphic is explained in the accompanying text The following tasks have been implemented in this method:

       1.      Read user inputs:

int I = wdContext.currentUIElemElement().getTypField();

int a = wdContext.currentUIElemElement().getA();

int b = wdContext.currentUIElemElement().getB();

1.       Read messages from the Message Manager:

MessageManager msgMgr =

             (MessageManager) wdThis.wdGetAPI().getComponent().getMessageManager();

 

2.       Does the input lie within the defined domain?

if (a < i && I < b)

3.       Call the This graphic is explained in the accompanying text standard message when the input lies within the domain:

MsgMgr.reportMessage(IMessageErrorhandlingTest1.KEY2, null);

Method reportMessage can be used to read the messages from the Message Manager. In this way you define the key and the objects that you want to change dynamically in the messages. Because no dynamic text was defined in your standard messages, you define null as a parameter.

4.       Call the This graphic is explained in the accompanying text warning messages when the input does not lie within the domain:

Object[] arg ={new Integer(a), new Integer(b)};

MsgMgr.reportMessage(IMessageErrorhandlingTest1.KEY1, arg);

Because the warning messages (This graphic is explained in the accompanying text Please enter a number between the range of  {0} and {1}!) contain text that depends on the user input, you also have to define the parameters for the domain in an object array. In the messages, the first object is then called from the array with {0} (and the second with {1}, and so on).

Result

After you have built and deployed your application, you can call it by choosing Run.

This graphic is explained in the accompanying text

If the user enters a number that lies within the defined domain, a standard message is displayed:

This graphic is explained in the accompanying text

 

If the user enters a number that does not lie within the defined domain, a warning message is displayed:

This graphic is explained in the accompanying text

  

  

 

End of Content Area