on 08-10-2012 8:29 PM
Hello Webdynpro experts!
We have a Web Dynpro application consisting of several views (V_MAIN, V_GENERATE, V_GENERATE_2).
The V_MAIN view contain a send button, and V_GENERATE_2 view contains some required fields.
We would like to check and highlight the required fields from V_GENERATE_2 when the user push the send button from the view V_MAIN.
Within Component controller we detected method CHECK_REQUIRED that checks the content of view V_GENERATE_2:
if ls_cc_req_context-REQ_CATEGORY = 'X' and ls_nd_add_context-CATEGORY is INITIAL.
lv_msg = WD_ASSIST->IF_WD_COMPONENT_ASSISTANCE~GET_TEXT( 'E15' ).
CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_ERROR_MESSAGE
EXPORTING
MESSAGE_TEXT = lv_msg
ELEMENT = lo_el_nd_add_context
ATTRIBUTE_NAME = 'CATEGORY'
endif.
Unfortunately this check does not check whether or not the required fields are empty.
We have heared about the the method cl_wd_dynamic_tool=>check_mandatory_attr_on_view, unfortunately we do not know how ans where (view) it should be declared.
Can some one help to solve this problem?
Hey Alex,
Code to Check mandatory fields in view is following...
It will display en error when any mandatory field is left as blank.
-> Go to method check_mandatory_attr_on_view of class cl_wd_dynamic_tool and check the type of exporting parameter MESSAGE , in your code declare an internal table of same time.
Write this logic to click action of button( Send )
method ONACTIONCLICK .
* Data declaration
data:
lo_view_controller type ref to if_wd_view_controller,
lo_dyn type ref to cl_wd_dynamic_tool.
* Create Object
create object lo_dyn.
data lt_messages type lo_dyn->t_check_result_message_tab.
* Get view controller reference
lo_view_controller = wd_this->wd_get_api( ).
* Call Method to verify the element has the value or not
call method cl_wd_dynamic_tool=>check_mandatory_attr_on_view
exporting
view_controller = lo_view_controller
display_messages = ABAP_TRUE
importing
messages = lt_messages .
endmethod.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
Class CL_WD_DYNAMIC_TOOL has two methods that might be of use to you.
You can get a reference to a view's controller by using the following statement in any of the view's methods, e.g., WDDOBEFOREACTION.
DATA lo_view_controller TYPE REF TO if_wd_view_controller,
lo_view_controller ?= wd_this->wd_get_api( ).
Cheers,
Amy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Amy,
many thanks!
and how can I check the attributes of the other view?
Is it also possible instead to adapt the existing method CHECK_REQUIRED that checks the content of view V_GENERATE_2?
if ls_cc_req_context-REQ_CATEGORY = 'X' and ls_nd_add_context-CATEGORY is INITIAL.
lv_msg = WD_ASSIST->IF_WD_COMPONENT_ASSISTANCE~GET_TEXT( 'E15' ).
CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_ERROR_MESSAGE
EXPORTING
MESSAGE_TEXT = lv_msg
ELEMENT = lo_el_nd_add_context
ATTRIBUTE_NAME = 'CATEGORY'
endif.
Thank you!
Hi Alex,
Your approach will depend on whether you defined the views' context nodes locally within the views themselves or defined the context nodes in the componentcontroller and then mapped the context nodes to the views. Here is one possible approach...
If you defined the context nodes in the componentcontroller (say node A and node B) and mapped the context nodes to the views (say node A is mapped to V_GENERATE and node B is mapped to V_GENERATE_2) when the user clicks the send button on V_MAIN, you could call a componentcontroller method to check the fields of both V_GENERATE and V_GENERATE_2 since the componentcontroller has access to both nodes A and B. In this example, the componentcontroller method would use CHECK_MANDATORY_ATTRIBUTES.
Cheers,
Amy
Hello,
I added the following code to the existing method WDDOBEFOREACTION
method _OVR_00O2TQKOM7ZWZBCIDL5IOQDYN .
data lo_api_controller type ref to if_wd_view_controller.
data lo_action type ref to if_wd_action.
lo_api_controller = wd_this->wd_get_api( ).
lo_action = lo_api_controller->get_current_action( ).
if lo_action is bound.
case lo_action->name.
when 'SEND_MESSAGE'.
CALL METHOD cl_wd_dynamic_tool=>check_mandatory_attr_on_view
EXPORTING
view_controller = lo_api_controller.
WD_COMP_CONTROLLER->CHECK_REQUIRED( ).
WD_COMP_CONTROLLER->CHECK_CUST_REQUIRED( ).
endcase.
endif.
endmethod.
Unfortunately this does not give any error for my mandatory field.
When I add display_messages = abap_true I get the error that display_messages is unknown.
It seams that I miss the DATA command.
I need some clarification please.
Thank you!
l_has_errors the return value for method 'check_mandatory_attributes' implies whether all the mandatory fields are entered.
DATA: attr_list TYPE STRING_TABLE.
data lt_messages type lo_dyn->t_check_result_message_tab.
DATA:
l_attr_list type CL_WD_DYNAMIC_TOOL=>t_check_mandattr_tab,
l_attr type CL_WD_DYNAMIC_TOOL=>t_check_mandattr_struct,
l_has_errors type wdy_boolean.
CALL METHOD cl_wd_dynamic_tool=>check_mandatory_attr_on_view
EXPORTING
view_controller = l_view_controller
display_messages = ABAP_false
IMPORTING
messages = lt_messages.
l_has_errors = cl_wd_dynamic_tool=>check_mandatory_attributes(
attribute_list = l_attr_list
display_messages = abap_FALSE
context_root = wd_context
).
if l_has_errors = 'X'.
"display the error message
endif.
Also lt_messages returns messages. I have used it to display the appropriate message with the fields details.
DATA : first_msg TYPE string VALUE 'Please enter the mandatory fields'.
data : secon_msg TYPE string.
FIELD-SYMBOLS: <lw_msg> LIKE LINE OF lt_messages.
LOOp at lt_messages ASSIGNING <lw_msg>.
CALL METHOD <lw_msg>-context_element->get_node
RECEIVING
node = lo_node.
CALL METHOD lo_node->get_node_info
RECEIVING
node_info = lo_node_info.
CALL METHOD lo_node_info->get_attribute
EXPORTING
name = <lw_msg>-attribute_name
RECEIVING
attribute_info = lw_attr_info.
APPEND <lw_msg>-attribute_name to attr_list.
CONCATENATE secon_msg <lw_msg>-attribute_name INTO secon_msg separated by ' ' .
ENDLOOP.
CONCATENATE first_msg secon_msg into first_msg.
lo_api_controller ?= wd_this->wd_get_api( ).
CALL METHOD lo_api_controller->get_message_manager
RECEIVING
message_manager = lo_message_manager
.
*
** report message
CALL METHOD lo_message_manager->report_element_error_message
EXPORTING
message_text = first_msg
element = lo_el_context
attributes = attr_list
.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
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.