on 2024 Jul 15 4:18 PM
Validation error messages in a behavior implementation are not displayed and elements are not highlighted.
In the behavior implementation for a draft enabled RAP based Fiori Elements application there is a custom check for mandatory fields. If a mandatory field is not filled, an error message should be displayed and the relevant element should be highlighted. The validation is executed correctly and the save action is stopped but only a generic error message ("Resolve data inconsistencies to save changes.") is displayed and no field is highlighted. When the app runs in preview mode via the Service Binding in Eclipse, the validation messages are correctly displayed and the relevant fields highlighted. The issue only occurs if the app runs in the Fiori Launchpad.
Behavior definition:
managed implementation in class zbp_i_product unique;
strict ( 2 );
with draft;
define behavior for ZI_Product alias product
persistent table za_product
draft table zd_product
authorization master ( instance )
lock master
total etag LastChangedAt
etag master LastChangedAt
{
create;
update;
delete;
field ( mandatory ) ProductName;
field ( readonly, numbering : managed ) ProductUuid;
field ( readonly ) CreatedBy, CreatedAt, LastChangedBy, LastChangedAt;
validation validateMandatoryFields on save { field ProductName create; }
mapping for za_product
{
ProductUuid = product_uuid;
ProductName = product_name;
ProductType = product_type;
CreatedBy = created_by;
CreatedAt = created_at;
LastChangedBy = last_changed_by;
LastChangedAt = last_changed_at;
}
draft determine action Prepare
{
validation validateMandatoryFields;
}
draft action Edit;
draft action Activate optimized;
draft action Discard;
draft action Resume;
}
Behavior implementation:
CLASS lhc_product DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS validatemandatoryfields FOR VALIDATE ON SAVE
IMPORTING keys FOR product~validatemandatoryfields.
ENDCLASS.
CLASS lhc_product IMPLEMENTATION.
METHOD validatemandatoryfields.
READ ENTITIES OF /zi_product IN LOCAL MODE
ENTITY product
FIELDS ( ProductName )
WITH CORRESPONDING #( keys )
RESULT DATA(products).
LOOP AT products ASSIGNING FIELD-SYMBOL(<product>).
APPEND VALUE #( %tky = <product>-%tky
%state_area = 'VALIDATE_MANDATORY' )
TO reported-product.
IF <product>-ProductName IS INITIAL.
APPEND VALUE #( %tky = <product>-%tky ) TO failed-product.
APPEND VALUE #( %tky = <product>-%tky
%state_area = 'VALIDATE_MANDATORY'
%msg = new_message( id = `ZPRODUCT`
number = 009
severity = if_abap_behv_message=>severity-error )
%element-ProductName= if_abap_behv=>mk-on ) TO reported-product.
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
The Fiori app is created as a Fiori Elements List Report based on an OData V4 service.
In my case Messages are displayed when %state_area is removed, but still fields are not highlighted.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.