on 05-29-2009 7:30 AM
Hi All,
In my web dynpro application I am displaying error messages but the focus does not go to the field where error occured and also if I click on the error message it does not lead to the place of error.
And also when I navigate to another view the error message does not go.
Below is my code:
* report message
DATA err1_text TYPE syst-msgv1.
err1_text = wd_assist->if_wd_component_assistance~get_text( key = '002' ).
CALL METHOD lo_message_manager->report_t100_message
EXPORTING
msgid = 'ZAA'
msgno = '005'
msgty = 'E'
p1 = err1_text
RECEIVING
message_id = lo_text.
Please suggest me the way to do it.
Thanks & Regards
Archana
You can use the method REPORT_ATTRIBUTE_T100_MESSAGE from the message manager interface IF_WD_MESSAGE_MANAGER. In this method you can specify the context attribute in the parameter ATTRIBUTE_NAME. Therefore it will highlight the input field.
For restricting the message to a view you need pass the view name in the parameter VIEW.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Archana,
Try using the report_attribute_error_message for throwing your error. Using this method the system would display all the error messages with a LinkToAction in the MessageArea. When the user clicks on the link the system would shift the focus to that particular element. Also all the elements where the error occured are highlighted in red coloured boxes. Refer the code snippet below:
For example in the code snippet below am looping through the records changed in an ALV and throwing an error message whenever the value entered is greater than or equal to 5.
Regards,
Uday
METHOD check_data.
DATA: lr_node TYPE REF TO if_wd_context_node,
lr_element TYPE REF TO if_wd_context_element,
ls_modified_cells TYPE salv_wd_s_table_mod_cell.
FIELD-SYMBOLS <temp> TYPE data.
* get message manager
DATA lo_api_controller TYPE REF TO if_wd_controller.
DATA lo_message_manager TYPE REF TO if_wd_message_manager.
lo_api_controller ?= wd_this->wd_get_api( ).
CALL METHOD lo_api_controller->get_message_manager
RECEIVING
message_manager = lo_message_manager.
lr_node = wd_context->get_child_node( name = 'NODE' ).
LOOP AT r_param->t_modified_cells INTO ls_modified_cells.
lr_element = lr_node->get_element( index = ls_modified_cells-index ).
IF ls_modified_cells-attribute = 'TEMP_NEW'.
ASSIGN ls_modified_cells-r_value->* TO <temp>.
IF <temp> GE 5.
* report message
CALL METHOD lo_message_manager->report_attribute_error_message
EXPORTING
message_text = 'You can only enter values which are less than 5!'
element = lr_element
attribute_name = ls_modified_cells-attribute.
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.
Hi Pooja,
Have a look at the code
lo_nd_year_list = wd_context->get_child_node( name = wd_this->wdctx_year_list ).
* get element via lead selection
lo_el_year_list = lo_nd_year_list->get_element( ).
* CHECK lo_el_year_list IS NOT INITIAL.
* get single attribute
lo_el_year_list->get_attribute(
EXPORTING
name = `YEAR`
IMPORTING
value = lv_year ).
* @TODO handle not set lead selection
IF lv_year IS INITIAL.
DATA lo_text TYPE string.
* get message manager
DATA lo_api_controller TYPE REF TO if_wd_controller.
DATA lo_message_manager TYPE REF TO if_wd_message_manager.
lo_api_controller ?= wd_this->wd_get_api( ).
CALL METHOD lo_api_controller->get_message_manager
RECEIVING
message_manager = lo_message_manager.
* report message
DATA ls_err TYPE symsg.
DATA err1_text TYPE symsgv.
err1_text = wd_assist->if_wd_component_assistance~get_text( key = '002' ).
ls_err-msgty = 'E'.
ls_err-msgid = 'ZAA'.
ls_err-msgno = '005'.
ls_err-msgv1 = err1_text.
CALL METHOD lo_message_manager->report_attribute_t100_message
EXPORTING
msg = ls_err
element = lo_el_year_list
attribute_name = `YEAR`
view = 'V_SEL_OPT'
RECEIVING
message_id = lo_text.
ENDIF.
After executing it gives following error:
"Access via 'NULL' object reference not possible."
HI,
What is the cardinality for that node.
If it is 0:N or 1:N then use the get the element at index then use the meesage.
case 1 * get element via lead selection
lo_el_year_list = lo_nd_year_list->get_element( index = lv_index ).
get element via lead selection
lo_el_year_list = lo_nd_year_list->get_element( ). -
Error as NULL reference
If it 1:1 cardinalty there is no need of index.
get element via lead selection
lo_el_year_list = lo_nd_year_list->get_element( ).
This works fine.
Regards,
Lekha.
Yes, its cardinality is 0:n.
I have done that index thing.
See here the element is refering to the drop down box, when I do indexing it automatically takes the 1st entry of that. and I dont want this automatic picking to be done as I want only user to enter and in case its blank it should display error.
In this scenario there would always be a value. I guess I am stuck in a cyclic problem.
Anyways thanks for your time.
If you have any solution for this please let me know.
Thanks & Regards
Archana
Hi,
One query...
This is a year drop down and you want to get the selected value from the dorpdown where user selects right.
Where have you written that code.
Have you written it in the drop down(onselection)event or any other event.
Have you used the get_lead_selection_index to get that index value.
Before you use any reference variable alwyas try to chekc if the element is initial or not.
Regards,
Lekha.
Hi Lekha,
I have coded for this in one of the componentcontroller methods .
Please see the code below:
DATA lt_year_list TYPE wd_this->elements_year_list.
DATA ls_year_list LIKE LINE OF lt_year_list .
DATA: year1 TYPE char4,
year2 TYPE char4,
year3 TYPE char4,
year TYPE sy-datum,
n TYPE char4,
z TYPE char4,
year_main TYPE char9.
year = sy-datum.
year1 = 1997.
year2 = 1998.
year3 = year+0(4).
n = year3 - year2.
z = n + 1.
DO z TIMES.
year1 = year1 + 1.
year2 = year2 + 1.
* ls_year_list-SLNO = 1.
ls_year_list-key1 = year1.
ls_year_list-key2 = year2.
CONCATENATE year1 '-' year2 INTO year_main.
ls_year_list-year = year_main.
APPEND ls_year_list TO lt_year_list.
ENDDO.
* bind a single element
node->bind_table(
new_items = lt_year_list
set_initial_elements = abap_true ).
Hi,
In the table entries there is an option for balnk value also. Is that right.
I was asking you about your previous code where you have handled the messages.
where have you wrriten that code in the dropdown(onselection event) or any where else..
lo_nd_year_list = wd_context->get_child_node( name = wd_this->wdctx_year_list ).
* get element via lead selection
lo_el_year_list = lo_nd_year_list->get_element( ).
* IF lo_el_year_list IS NOT INITIAL.
* get single attribute
lo_el_year_list->get_attribute(
EXPORTING
name = `YEAR`
IMPORTING
value = lv_year ).
* @TODO handle not set lead selection
IF lv_year IS INITIAL.
DATA lo_text TYPE string.
* get message manager
DATA lo_api_controller TYPE REF TO if_wd_controller.
DATA lo_message_manager TYPE REF TO if_wd_message_manager.
lo_api_controller ?= wd_this->wd_get_api( ).
CALL METHOD lo_api_controller->get_message_manager
RECEIVING
message_manager = lo_message_manager.
* report message
DATA ls_err TYPE symsg.
DATA err1_text TYPE symsgv.
err1_text = wd_assist->if_wd_component_assistance~get_text( key = '002' ).
ls_err-msgty = 'E'.
ls_err-msgid = 'ZAA'.
ls_err-msgno = '005'.
ls_err-msgv1 = err1_text.
CALL METHOD lo_message_manager->report_attribute_t100_message
EXPORTING
msg = ls_err
element = lo_el_year_list
attribute_name = `YEAR`
view = 'V_SEL_OPT'
RECEIVING
message_id = lo_text.
ENDIF.
endif. " lo_el_year_list not intial.
Regards,
Lekha.
>
> Hi
> There is no blank entry in the drop down. The drop down code and the message generation are in different methods.
>
> The method is generated on onaction event which occurs after clicking button in the UI .
The correction is :
The 'message' is generated on onaction event which occurs after clicking button in the UI.
Hi,
You are raising the error in the Button handler right.
How can you get to know what the user has selected from the dropdown.
This can be handled only by getting the index right.
If there are no entries in the table with blank record then why you want to test the user has selected none from dropdown.
IS there any entry as <<SELECTED NONE>>/<<SELECT ONE>> or such entry where you want to test the element is initial so that you can throw the eror meesgae that Nothg is selected.
You can handle the code in the Button handler only by getting the element at that index as 0:N caridnality is there.
Regards,
Lekha.
Hi,
I got your point.. in the BIND_TABLE( set_intiail_elemts = abap_true) change this to ABAP_FALSE.
Because of this you are gettng the intiial values. Eventhough your table has no BALNK/space records.
bind a single element
node->bind_table(
new_items = lt_year_list
set_initial_elements = abap_true ).
change as
bind a single element
node->bind_table(
new_items = lt_year_list
set_initial_elements = abap_false ).
You can use this code - I have tjhe dropdwon for projects event I'm doing the same.
navigate from <CONTEXT> to <PROJECT> via lead selection
lo_nd_project = wd_context->get_child_node( 'PROJECT' ).
***Gets the selected project id from drop down
if lo_nd_project is not initial.
CALL METHOD lo_nd_project->GET_LEAD_SELECTION
RECEIVING
ELEMENT = lo_el_project.
get all declared attributes
if lo_el_project is not initial.
lo_el_project->get_static_attributes(
IMPORTING
static_attributes = ls_project ).
change your code to
lo_nd_year_list = wd_context->get_child_node( name = wd_this->wdctx_year_list ).
***Gets the selected project id from drop down
if lo_nd_year_list is not initial.
CALL METHOD lo_nd_year_list->GET_LEAD_SELECTION
RECEIVING
ELEMENT = lo_el_year_list .
IF lo_el_year_list IS NOT INITIAL.
get single attribute
lo_el_year_list->get_attribute(
EXPORTING
name = `YEAR`
IMPORTING
value = lv_year ).
Regards,
Lekha.
So you can accordingly use the same logic to check for when your element has a NULL value & throw an error message using report_attribute_error_message.
Also regarding the problem that you had with the messages still being on shown after navigating to another view. Try specifying even your views name in the parameter VIEW while calling REPORT_T100_MESSAGE. But you wouldn't be able to realize the functionality of shifting focus to the desired element by using REPORT_T100_MESSAGE. You need to make use REPORT_ATTRIBUTE_ERROR_MESSAGE for achieving that functionality. The ELEMENT & ATTRIBUTE_NAME are the important one's while using this method.
Regards,
Uday
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Refer the following thread: https://forums.sdn.sap.com/click.jspa?searchID=26746792&messageID=7407704
I hope it helps.
Regards
Arjun
Edited by: Arjun Thakur on May 29, 2009 12:19 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.