Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

Handling error messages

In the previous application we saw how to navigate from one view to another.

In this blog we will see how to handle the message. In the previous application user enters the name in the first screen and submit the name will be displayed in the second screen. Now let us make the name input as mandatory and if name is not enter we will block the navigation to the second view and throw an error message.

In order to display the error message in our required space we need to insert the message area UI element. In case if this UI element is not place message will be displayed by default on the top of the page.

Now let’s move to the application.

In order to make the input field as mandatory, change the state of the Input field UI element as required from normal. You will be able to see a red star indicating the field as mandatory in its associated label. However the mandatory fields are not checked for emptiness by default in SAP Webdynpro like in normal ABAP. We have to incorporate the logic in our method to check for the emptiness of the fields. There is also some standard class which is used to check the mandatory fields in the screen which you will see in the later blogs.

Step1: Go to the view and change the property of the input field.

clip_image001

clip_image002

Step 2: Insert a message area UI element.

clip_image003

clip_image004

Step 3: In the event handler method for the submit button check for the emptiness of the input field and throw an error message.

Modify the code as below.

clip_image005

In the else part generate the error message using the message manager in the code wizard.

Select the radio button generate message and choose a method report_error_message from the F4.

clip_image006

Code will be generated as below.

clip_image007

Note: I have removed the dead codes and comments,

Pass the error message you want to display using the parameter message_text.

clip_image008

Save and activate the application. Test the component.

clip_image009

Output:

clip_image009[1]

Enter Submit without entering name.

clip_image010

You can see the error messages generated where we have placed the message area.

Remove the message area UI element and test the application the error message by default will be displayed on the top.

 

About Arun

2 Comments:

  1. i can suggest
    1)success messages
    2) warning messages
    these posts are also inserted because in interview point these two topics are also important

    ReplyDelete
  2. CAN YOU DISPLAY ERROR MSG IN POPUP .
    I TRIED USING ' SHOW_AS_POPUP ' FIELD IN SAME METHOD BUT WAS UNABLE TO DISPLAY.

    ReplyDelete

Powered by Blogger.